Compare commits

..

No commits in common. "ce17e9dc73e7f229a95e0b3c4f044616f88029d5" and "52dfb7e0f2e03ea209ae3c1c92f68ae1d1d24003" have entirely different histories.

9 changed files with 14 additions and 45 deletions

View File

@ -44,9 +44,6 @@ func main() {
ID: uuid.NewString(),
Code: "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"`
StartDate time.Time `gorm:"default:CURRENT_TIMESTAMP"`
EndDate time.Time `gorm:"default:null"`
Status int8 `gorm:"default:0"`
Status string `gorm:"default:'inactive'"`
AutoRenew bool `gorm:"default:true"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
@ -22,9 +22,6 @@ type SubscribePlan struct {
ID string `gorm:"primaryKey" json:"id"`
Code string `gorm:"not null;unique" json:"code"`
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"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

View File

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

View File

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

View File

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

View File

@ -6,9 +6,6 @@ type SubscribePlan struct {
ID string `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Length int `json:"length"`
Price float32 `json:"price"`
Status int8 `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
@ -16,16 +13,10 @@ type SubscribePlan struct {
type SubscribePlanUpdate struct {
Code string `json:"code" 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"`
}
type SubscribePlanReq struct {
Code string `json:"code" 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 {
ID string `json:"id"`
Status int8 `json:"status"`
Status string `json:"status"`
SubscribePlanID string `json:"subscribe_plan_id"`
AutoRenew bool `json:"auto_renew"`
StartDate time.Time `json:"start_date"`

View File

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

View File

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