Compare commits

..

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

9 changed files with 14 additions and 45 deletions

View File

@ -41,12 +41,9 @@ 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 int8 `gorm:"default:0"` Status string `gorm:"default:'inactive'"`
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,9 +22,6 @@ 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).Error; err != nil { Update("subscribe_plan_id", basicPlan.ID); 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.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) 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{ DoUpdates: clause.AssignmentColumns([]string{
"name", "name",
"code", "code",
"length",
"price",
"status",
"updated_at", "updated_at",
}), }),
}).Select( }).Select("name", "code", "updated_at").Save(&spec).Error; err != nil {
"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 int8 `json:"status"` Status string `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,9 +6,6 @@ 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"`
} }
@ -16,16 +13,10 @@ 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 int8 `json:"status"` Status string `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,12 +8,9 @@ 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,9 +10,6 @@ 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)