first
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Package orders lets a customer (connected or not, per spec section 17-19)
|
||||
// place an order directly from the storefront, and lets the admin track
|
||||
// and update it. Pricing is never trusted from the client: each line is
|
||||
// resolved against the pricing module's authoritative price tier at
|
||||
// creation time.
|
||||
package orders
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusPending = "pending"
|
||||
StatusConfirmed = "confirmed"
|
||||
StatusPreparing = "preparing"
|
||||
StatusShipped = "shipped"
|
||||
StatusCompleted = "completed"
|
||||
StatusCancelled = "cancelled"
|
||||
)
|
||||
|
||||
var ValidStatuses = map[string]bool{
|
||||
StatusPending: true,
|
||||
StatusConfirmed: true,
|
||||
StatusPreparing: true,
|
||||
StatusShipped: true,
|
||||
StatusCompleted: true,
|
||||
StatusCancelled: true,
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
||||
CustomerName string `gorm:"not null"`
|
||||
CustomerEmail string `gorm:"not null"`
|
||||
CustomerPhone string `gorm:"not null;default:''"`
|
||||
Status string `gorm:"not null;default:pending"`
|
||||
TotalCents int64 `gorm:"not null;default:0"`
|
||||
Notes string `gorm:"not null;default:''"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (Order) TableName() string { return "orders" }
|
||||
|
||||
// OrderItem snapshots the product name, unit symbol and unit price at order
|
||||
// time, so the order stays accurate even if the product/unit is later
|
||||
// renamed or deleted.
|
||||
type OrderItem struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
||||
OrderID uuid.UUID `gorm:"type:uuid;not null;index"`
|
||||
ProductID *uuid.UUID `gorm:"type:uuid"`
|
||||
ProductName string `gorm:"not null"`
|
||||
PriceTierID *uuid.UUID `gorm:"type:uuid"`
|
||||
UnitSymbol string `gorm:"not null"`
|
||||
TierQuantity float64 `gorm:"not null"`
|
||||
Multiplier int64 `gorm:"not null;default:1"`
|
||||
UnitPriceCents int64 `gorm:"not null"`
|
||||
TotalCents int64 `gorm:"not null"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (OrderItem) TableName() string { return "order_items" }
|
||||
Reference in New Issue
Block a user