mirror of
https://github.com/marcusDenslow/terminalShop.git
synced 2026-10-26 02:08:46 +01:00
feat: implement server-side cart persistence with Stripe PaymentIntents Replaced the client-only in-mem cart with a database-backed cart system - Add Cart and CartItem GORM models (two-table design) - Add 6 cart API endpoints (get, set item, set address, set card, clear, conver) - Switch from Stripe Charge API to PaymentIntents with confirm:true - Add 9 API client methods for cart and card operations - Refactor TUI cart from map[int] (slice index) to map[uint] (CoffeeID) - Replace single-shot checkout with saveCardAndConvert multi-step flow - Add CheckingOut state with "submitting order..." processing indicator - Fix Stripe tokenization to use secret key for server-side SSH apps - Remove admin product CRUD endpoints and old checkout handler
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Cart struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
UserID uint `gorm:"uniqueIndex;not null" json:"user_id"`
|
|
AddressID *uint `json:"address_id,omitempty"`
|
|
CardID *uint `json:"card_id,omitempty"`
|
|
ShippingCost int `gorm:"default:0" json:"shipping_cost"`
|
|
ShippingService string `gorm:"size:255" json:"shipping_service,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
User User `gorm:"foreignKey:UserID" json:"-"`
|
|
Address *Address `gorm:"foreignKey:AddressID" json:"address,omitempty"`
|
|
Card *Card `gorm:"foreignKey:CardID" json:"card,omitempty"`
|
|
Items []CartItem `gorm:"foreignKey:CartID" json:"items"`
|
|
}
|
|
|
|
// TableName specifies the table name for the Cart model.
|
|
func (Cart) TableName() string {
|
|
return "carts"
|
|
}
|
|
|
|
type CartItem struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
CartID uint `gorm:"not null;index;uniqueIndex:idx_cart_coffee" json:"cart_id"`
|
|
CoffeeID uint `gorm:"not null;uniqueIndex:idx_cart_coffee" json:"coffee_id"`
|
|
Quantity int `gorm:"not null" json:"quantity"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
Cart Cart `gorm:"foreignKey:CartID" json:"-"`
|
|
Coffee Coffee `gorm:"foreignKey:CoffeeID" json:"coffee"`
|
|
}
|
|
|
|
func (CartItem) TableName() string {
|
|
return "cart_items"
|
|
}
|