Compare commits

...

2 Commits

Author SHA1 Message Date
ericprd
ce17e9dc73 fix: update seeder 2025-03-10 12:28:56 +08:00
ericprd
ce341dbc13 fix: add new fields on subscribe plan, and change status type to number in subscribe 2025-03-10 11:48:20 +08:00
9 changed files with 45 additions and 14 deletions

View File

@ -41,9 +41,12 @@ func main() {
if err := db.Where("code = ?", "basic").First(&temp).Error; err != nil { if err := db.Where("code = ?", "basic").First(&temp).Error; err != nil {
log.Print("seeding basic subscribe plan") log.Print("seeding basic subscribe plan")
db.Create(&subscribeplandomain.SubscribePlan{ db.Create(&subscribeplandomain.SubscribePlan{
ID: uuid.NewString(), ID: uuid.NewString(),
Code: "basic", Code: "basic",
Name: "Basic", Name: "Basic",
Length: 0,
Price: 0,
Status: 1,
}) })
} }

View File

@ -9,7 +9,7 @@ type Subscribe struct {
SubscribePlanID string `gorm:"not null" json:"subscribe_plan_id"` SubscribePlanID string `gorm:"not null" json:"subscribe_plan_id"`
StartDate time.Time `gorm:"default:CURRENT_TIMESTAMP"` StartDate time.Time `gorm:"default:CURRENT_TIMESTAMP"`
EndDate time.Time `gorm:"default:null"` EndDate time.Time `gorm:"default:null"`
Status string `gorm:"default:'inactive'"` Status int8 `gorm:"default:0"`
AutoRenew bool `gorm:"default:true"` AutoRenew bool `gorm:"default:true"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"` CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"` UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
@ -22,6 +22,9 @@ type SubscribePlan struct {
ID string `gorm:"primaryKey" json:"id"` ID string `gorm:"primaryKey" json:"id"`
Code string `gorm:"not null;unique" json:"code"` Code string `gorm:"not null;unique" json:"code"`
Name string `gorm:"not null" json:"name"` Name string `gorm:"not null" json:"name"`
Length int `gorm:"default:0" json:"length"`
Price float32 `gorm:"default:0" json:"price"`
Status int8 `gorm:"default:1" json:"status"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"` CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"` UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
} }

View File

@ -18,11 +18,11 @@ func (a *accessor) Delete(id string) error {
if err := a.db. if err := a.db.
Model(&subscribedomain.Subscribe{}). Model(&subscribedomain.Subscribe{}).
Where("subscribe_plan_id = ?", id). Where("subscribe_plan_id = ?", id).
Update("subscribe_plan_id", basicPlan.ID); err != nil { Update("subscribe_plan_id", basicPlan.ID).Error; err != nil {
return fmt.Errorf("failed to change subscribe plan: %v", err) return fmt.Errorf("failed to change subscribe plan: %v", err)
} }
if err := a.db.Where("id = ?", id).Delete(&subsPlan).Error; err != nil { if err := a.db.Delete(&subsPlan, "id = ?", id).Error; err != nil {
return fmt.Errorf("failed to delete subscribe plan %s : %v", id, err) return fmt.Errorf("failed to delete subscribe plan %s : %v", id, err)
} }

View File

@ -13,9 +13,19 @@ func (a *accessor) Update(spec subscribeplandomain.SubscribePlan) error {
DoUpdates: clause.AssignmentColumns([]string{ DoUpdates: clause.AssignmentColumns([]string{
"name", "name",
"code", "code",
"length",
"price",
"status",
"updated_at", "updated_at",
}), }),
}).Select("name", "code", "updated_at").Save(&spec).Error; err != nil { }).Select(
"name",
"code",
"length",
"price",
"status",
"updated_at",
).Save(&spec).Error; err != nil {
return fmt.Errorf("failed to update tag: %v", err) return fmt.Errorf("failed to update tag: %v", err)
} }

View File

@ -10,7 +10,7 @@ type Subscribe struct {
SubscribePlanID string `json:"subscribe_plan_id"` SubscribePlanID string `json:"subscribe_plan_id"`
StartDate time.Time `json:"start_date"` StartDate time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"` EndDate *time.Time `json:"end_date"`
Status string `json:"status"` Status int8 `json:"status"`
AutoRenew bool `json:"auto_renew"` AutoRenew bool `json:"auto_renew"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`

View File

@ -6,6 +6,9 @@ type SubscribePlan struct {
ID string `json:"id"` ID string `json:"id"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
Length int `json:"length"`
Price float32 `json:"price"`
Status int8 `json:"status"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
} }
@ -13,10 +16,16 @@ type SubscribePlan struct {
type SubscribePlanUpdate struct { type SubscribePlanUpdate struct {
Code string `json:"code" validate:"required"` Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
Length int `json:"length"`
Price float32 `json:"price"`
Status int8 `json:"status"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
} }
type SubscribePlanReq struct { type SubscribePlanReq struct {
Code string `json:"code" validate:"required"` Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
Status int8 `json:"status"`
Length int `json:"length"`
Price float32 `json:"price"`
} }

View File

@ -37,7 +37,7 @@ type UserLogin struct {
type UserSubsUpdate struct { type UserSubsUpdate struct {
ID string `json:"id"` ID string `json:"id"`
Status string `json:"status"` Status int8 `json:"status"`
SubscribePlanID string `json:"subscribe_plan_id"` SubscribePlanID string `json:"subscribe_plan_id"`
AutoRenew bool `json:"auto_renew"` AutoRenew bool `json:"auto_renew"`
StartDate time.Time `json:"start_date"` StartDate time.Time `json:"start_date"`

View File

@ -8,9 +8,12 @@ import (
func (sb *impl) Create(spec subscribeplandomain.SubscribePlanReq) error { func (sb *impl) Create(spec subscribeplandomain.SubscribePlanReq) error {
data := subscribeplandomain.SubscribePlan{ data := subscribeplandomain.SubscribePlan{
ID: uuid.NewString(), ID: uuid.NewString(),
Code: spec.Code, Code: spec.Code,
Name: spec.Name, Name: spec.Name,
Length: spec.Length,
Price: spec.Price,
Status: spec.Status,
} }
return sb.subsRepo.Create(data) return sb.subsRepo.Create(data)
} }

View File

@ -10,6 +10,9 @@ func (i *impl) Update(id string, spec subscribeplandomain.SubscribePlanUpdate) e
ID: id, ID: id,
Code: spec.Code, Code: spec.Code,
Name: spec.Name, Name: spec.Name,
Length: spec.Length,
Price: spec.Price,
Status: spec.Status,
UpdatedAt: timeutils.Now(), UpdatedAt: timeutils.Now(),
} }
return i.subsRepo.Update(newData) return i.subsRepo.Update(newData)