From c302dc7b8e22587c5f00652629173cc2ce38cc67 Mon Sep 17 00:00:00 2001 From: DacongDA Date: Tue, 7 May 2024 23:33:01 +0800 Subject: [PATCH] fix: fix bug when init plan and pricing and record (#2934) * fix: fix potential bugs in init data * fix: improve code format * fix: fix bug when init plan and pricing and record --- object/init_data.go | 5 +++-- object/plan.go | 2 +- object/pricing.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/object/init_data.go b/object/init_data.go index 7ba6f377..a7d4004a 100644 --- a/object/init_data.go +++ b/object/init_data.go @@ -666,7 +666,7 @@ func initDefinedPlan(plan *Plan) { panic(err) } if !affected { - panic("Fail to delete enforcer") + panic("Fail to delete plan") } } plan.CreatedTime = util.GetCurrentTime() @@ -677,7 +677,7 @@ func initDefinedPlan(plan *Plan) { } func initDefinedPricing(pricing *Pricing) { - existed, err := getPlan(pricing.Owner, pricing.Name) + existed, err := getPricing(pricing.Owner, pricing.Name) if err != nil { panic(err) } @@ -719,6 +719,7 @@ func initDefinedInvitation(invitation *Invitation) { } func initDefinedRecord(record *casvisorsdk.Record) { + record.Id = 0 record.CreatedTime = util.GetCurrentTime() _ = AddRecord(record) } diff --git a/object/plan.go b/object/plan.go index 1f905068..861f69b9 100644 --- a/object/plan.go +++ b/object/plan.go @@ -133,7 +133,7 @@ func AddPlan(plan *Plan) (bool, error) { } func DeletePlan(plan *Plan) (bool, error) { - affected, err := ormer.Engine.ID(core.PK{plan.Owner, plan.Name}).Delete(plan) + affected, err := ormer.Engine.ID(core.PK{plan.Owner, plan.Name}).Delete(Plan{}) if err != nil { return false, err } diff --git a/object/pricing.go b/object/pricing.go index 8d79eba1..935488f4 100644 --- a/object/pricing.go +++ b/object/pricing.go @@ -140,7 +140,7 @@ func AddPricing(pricing *Pricing) (bool, error) { } func DeletePricing(pricing *Pricing) (bool, error) { - affected, err := ormer.Engine.ID(core.PK{pricing.Owner, pricing.Name}).Delete(pricing) + affected, err := ormer.Engine.ID(core.PK{pricing.Owner, pricing.Name}).Delete(Pricing{}) if err != nil { return false, err }