feat: add order and order_item models
@@ -20,5 +20,11 @@ func InitDB() {
|
|||||||
log.Fatal("Failed to connect to database:", err)
|
log.Fatal("Failed to connect to database:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.AutoMigrate(&models.Item{}, &models.User{}, &models.CartItem{})
|
DB.AutoMigrate(
|
||||||
|
&models.Item{},
|
||||||
|
&models.User{},
|
||||||
|
&models.CartItem{},
|
||||||
|
&models.Order{},
|
||||||
|
&models.OrderItem{},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Order struct {
|
||||||
|
ID uint `json:"id" gorm:"primaryKey"`
|
||||||
|
UserID uint `json:"user_id" gorm:"not null;index"`
|
||||||
|
Status string `json:"status" gorm:"not null"`
|
||||||
|
DeliveryAddress string `json:"delivery_address" gorm:"not null"`
|
||||||
|
TotalPrice float64 `json:"total_price" gorm:"not null"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
Items []OrderItem
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderItem struct {
|
||||||
|
ID uint `json:"id" gorm:"primaryKey"`
|
||||||
|
OrderID uint `json:"order_id" gorm:"not null;index"`
|
||||||
|
ItemID uint `json:"item_id" gorm:"not null;index"`
|
||||||
|
Quantity float64 `json:"quantity" gorm:"not null"`
|
||||||
|
Price float64 `json:"price" gorm:"not null"`
|
||||||
|
Item Item `json:"item" gorm:"foreignKey:ItemID"`
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 9.8 MiB |
|
Before Width: | Height: | Size: 138 KiB |
|
Before Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 741 KiB |
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 328 KiB |
|
Before Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 279 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 139 KiB |
|
Before Width: | Height: | Size: 52 KiB |