Files
template-vitrine/backend/internal/modules/orders/model.go
T
Xor290 919c807004
ci-api / test (push) Failing after 8m7s
ci-web / test (push) Failing after 5m5s
chore: build
2026-09-20 12:18:33 +02:00

49 lines
1.8 KiB
Go

// Package orders lets a customer 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.
//
// Whether an order requires a logged-in (and possibly identity-verified)
// customer account is an admin-configurable gate, not a fixed rule of this
// package -- see gate.go and site.Settings.CustomerAccountsEnabled.
package orders
import (
"time"
"github.com/google/uuid"
)
type Order struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
CustomerID *uuid.UUID `gorm:"type:uuid;index"`
CustomerName string `gorm:"not null"`
CustomerEmail string `gorm:"not null"`
CustomerPhone string `gorm:"not null;default:''"`
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" }