Skip to content

Commit

Permalink
Fixed some tables
Browse files Browse the repository at this point in the history
  • Loading branch information
HirbodBehnam committed Dec 26, 2023
1 parent a9537b3 commit 30445c4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions payment/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Payment service
1 change: 1 addition & 0 deletions payment/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package api
1 change: 1 addition & 0 deletions payment/internal/database/payment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package database
2 changes: 1 addition & 1 deletion payment/internal/database/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
26 changes: 16 additions & 10 deletions payment/internal/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import (
"time"
)

type PayedGood uint8

const (
PayedGoodOnlineAttendance PayedGood = 0
PayedGoodInPersonAttendance PayedGood = 1
)

type PaymentStatus uint8

const (
Expand All @@ -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
}

0 comments on commit 30445c4

Please sign in to comment.