Products like fish are sold per weighing (4.2 ons, 5.6 ons), which the order line could not represent: quantity is INTEGER and prices are always computed as quantity * unit_price. Model one weighing as one order line. quantity stays INTEGER and keeps meaning "how many items"; the measured amount goes into a new nullable order_items.weight, and the line is priced weight * unit_price. Two weighings of the same product are two lines, never merged into one. Keeping quantity integral avoids float comparisons in void, refund and split bill, where accumulated rounding error would silently misbehave — "1.4 + 1.4 + 1.4" is not 4.2 in float64, which would leave a fully paid split-bill item marked unpaid. BillableQuantity() is now the single place that decides between weight and count; every price and cost calculation goes through it. Missing one would bill a 4.2 ons fish as a single ons — wrong money, no error. Two database constraints back the design: a weighed line always carries a positive weight, and its quantity is pinned to 1. The latter also makes void all-or-nothing for weighed lines, so the row-splitting branch can never produce a zero-weight remainder row. Also wires product.unit_id through the API, which was previously not settable at all, and corrects the misleading comment on the request's unit_price field — that value has never been used; price always comes from the database. Design notes and the audit of every price multiplication site are in docs/rfc-weight-based-products.md. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
package contract
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type SelfOrderTableTokenResponse struct {
|
|
SessionID string `json:"session_id"`
|
|
TableID string `json:"table_id"`
|
|
OrganizationID string `json:"organization_id"`
|
|
OutletID string `json:"outlet_id"`
|
|
TableName string `json:"table_name"`
|
|
OutletName string `json:"outlet_name"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type SelfOrderMenuRequest struct {
|
|
SessionID string `form:"session_id" validate:"required"`
|
|
}
|
|
|
|
type SelfOrderMenuResponse struct {
|
|
OutletName string `json:"outlet_name"`
|
|
TableName string `json:"table_name"`
|
|
Categories []SelfOrderMenuCategory `json:"categories"`
|
|
}
|
|
|
|
type SelfOrderMenuCategory struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
Order int `json:"order"`
|
|
Products []SelfOrderMenuItem `json:"products"`
|
|
}
|
|
|
|
type SelfOrderMenuItem struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
Price float64 `json:"price"`
|
|
ImageURL *string `json:"image_url,omitempty"`
|
|
Variants []SelfOrderMenuVariant `json:"variants,omitempty"`
|
|
}
|
|
|
|
type SelfOrderMenuVariant struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
PriceModifier float64 `json:"price_modifier"`
|
|
}
|
|
|
|
type SelfOrderCreateOrderRequest struct {
|
|
SessionID string `json:"session_id" validate:"required"`
|
|
CustomerName string `json:"customer_name" validate:"required"`
|
|
OrderType string `json:"order_type" validate:"required,oneof=dine_in takeaway delivery"`
|
|
OrderItems []SelfOrderCreateOrderItem `json:"order_items" validate:"required,min=1,dive"`
|
|
}
|
|
|
|
type SelfOrderCreateOrderItem struct {
|
|
ProductID uuid.UUID `json:"product_id" validate:"required"`
|
|
ProductVariantID *uuid.UUID `json:"product_variant_id,omitempty"`
|
|
Quantity int `json:"quantity" validate:"required,min=1"`
|
|
Weight *float64 `json:"weight,omitempty" validate:"omitempty,gt=0"`
|
|
Notes *string `json:"notes,omitempty"`
|
|
}
|
|
|
|
type SelfOrderListCategoriesRequest struct {
|
|
OrganizationID string `form:"organization_id" validate:"required"`
|
|
OutletID string `form:"outlet_id" validate:"required"`
|
|
}
|
|
|
|
type SelfOrderCategoryItem struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
Order int `json:"order"`
|
|
}
|
|
|
|
type SelfOrderListCategoriesResponse struct {
|
|
Categories []SelfOrderCategoryItem `json:"categories"`
|
|
}
|
|
|
|
type SelfOrderListOrdersResponse struct {
|
|
Orders []OrderResponse `json:"orders"`
|
|
}
|