feat: add order and order_item models

This commit is contained in:
2026-06-23 09:43:20 +03:00
parent a73d147e12
commit 66070c2e73
17 changed files with 32 additions and 1 deletions
+7 -1
View File
@@ -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{},
)
} }
+25
View File
@@ -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"`
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 741 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB