From 30445c46f4a3d45e866025b9ec5843f1c7519e9d Mon Sep 17 00:00:00 2001 From: Hirbod Behnam Date: Tue, 26 Dec 2023 12:43:02 +0330 Subject: [PATCH] Fixed some tables --- payment/README.MD | 1 + payment/api/types.go | 1 + payment/internal/database/payment.go | 1 + payment/internal/database/pg.go | 2 +- payment/internal/database/types.go | 26 ++++++++++++++++---------- 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 payment/README.MD create mode 100644 payment/api/types.go create mode 100644 payment/internal/database/payment.go diff --git a/payment/README.MD b/payment/README.MD new file mode 100644 index 00000000..029db6e3 --- /dev/null +++ b/payment/README.MD @@ -0,0 +1 @@ +# Payment service \ No newline at end of file diff --git a/payment/api/types.go b/payment/api/types.go new file mode 100644 index 00000000..778f64ec --- /dev/null +++ b/payment/api/types.go @@ -0,0 +1 @@ +package api diff --git a/payment/internal/database/payment.go b/payment/internal/database/payment.go new file mode 100644 index 00000000..636bab89 --- /dev/null +++ b/payment/internal/database/payment.go @@ -0,0 +1 @@ +package database diff --git a/payment/internal/database/pg.go b/payment/internal/database/pg.go index 568fc68b..cc6a8324 100644 --- a/payment/internal/database/pg.go +++ b/payment/internal/database/pg.go @@ -14,7 +14,7 @@ func NewPostgres(dsn string) (*gorm.DB, error) { return nil, errors.Wrap(err, "cannot open database") } // Gorm automatically pings the database thus we can just migrate tables - err = db.AutoMigrate(&Payment{}) + err = db.AutoMigrate(Good{}, Payment{}) if err != nil { return nil, errors.Wrap(err, "cannot migrate database") } diff --git a/payment/internal/database/types.go b/payment/internal/database/types.go index a702ee95..66b96c39 100644 --- a/payment/internal/database/types.go +++ b/payment/internal/database/types.go @@ -5,13 +5,6 @@ import ( "time" ) -type PayedGood uint8 - -const ( - PayedGoodOnlineAttendance PayedGood = 0 - PayedGoodInPersonAttendance PayedGood = 1 -) - type PaymentStatus uint8 const ( @@ -24,23 +17,36 @@ const ( // Payment represents a payment made by a user type Payment struct { // The order ID which is sent to pay.ir - OrderID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` + ID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` // Who has made this payment? UserID uint64 `gorm:"index;not null"` // What is the amount that the user should pay? ToPayAmount uint64 `gorm:"not null"` + // The amount which we got a discount + Discount uint64 // An optional description about this payment Description string // The track ID which idpay returns to us after verification TrackID string // The payment track ID which idpay returns to us after verification PaymentTrackID string - // What product this user is buying - GoodType PayedGood `gorm:"not null"` // What is the status of this payment? PaymentStatus PaymentStatus `gorm:"not null"` + // List of the Goos which this user has bought in this payment + BoughtGoods []Good `gorm:"many2many:bought_goods;"` // When was this payment created? CreatedAt time.Time `gorm:"not null"` // When was it verified? (could be null) VerifiedAt time.Time } + +type Good struct { + // ID of this good + ID uint32 `gorm:"primarykey"` + // Name of it + Name string `gorm:"unique;not null"` + // The price of this item + Price uint64 `gorm:"not null"` + // An optional description about this payment + Description string +}