fix: add new fields on subscribe plan, and change status type to number in subscribe

This commit is contained in:
ericprd
2025-03-10 11:48:20 +08:00
parent 52dfb7e0f2
commit ce341dbc13
8 changed files with 39 additions and 11 deletions
+2 -2
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); err != nil {
Update("subscribe_plan_id", basicPlan.ID).Error; err != nil {
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)
}
+11 -1
View File
@@ -13,9 +13,19 @@ func (a *accessor) Update(spec subscribeplandomain.SubscribePlan) error {
DoUpdates: clause.AssignmentColumns([]string{
"name",
"code",
"length",
"price",
"status",
"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)
}
+1 -1
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 string `json:"status"`
Status int8 `json:"status"`
AutoRenew bool `json:"auto_renew"`
UpdatedAt time.Time `json:"updated_at"`
+11 -2
View File
@@ -6,6 +6,9 @@ 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"`
}
@@ -13,10 +16,16 @@ 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"`
Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"`
Status int8 `json:"status"`
Length int `json:"length"`
Price float32 `json:"price"`
}
+1 -1
View File
@@ -37,7 +37,7 @@ type UserLogin struct {
type UserSubsUpdate struct {
ID string `json:"id"`
Status string `json:"status"`
Status int8 `json:"status"`
SubscribePlanID string `json:"subscribe_plan_id"`
AutoRenew bool `json:"auto_renew"`
StartDate time.Time `json:"start_date"`
+6 -3
View File
@@ -8,9 +8,12 @@ import (
func (sb *impl) Create(spec subscribeplandomain.SubscribePlanReq) error {
data := subscribeplandomain.SubscribePlan{
ID: uuid.NewString(),
Code: spec.Code,
Name: spec.Name,
ID: uuid.NewString(),
Code: spec.Code,
Name: spec.Name,
Length: spec.Length,
Price: spec.Price,
Status: spec.Status,
}
return sb.subsRepo.Create(data)
}
@@ -10,6 +10,9 @@ 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)