package models import ( "fmt" "time" ) type Tag struct { ID int Name string } type Cake struct { Name string ID int Price Price // increments of 0.01 Amount int Tags []Tag } type SpecialCake struct { ID int OrderID int Name string Price Price Size string Shape string Flavour string Notes string Tags []Tag } func (s SpecialCake) Detail() string { parts := make([]string, 0, 4) if s.Size != "" { parts = append(parts, s.Size) } if s.Flavour != "" { parts = append(parts, s.Flavour) } if s.Shape == "square" { parts = append(parts, "kwadrat") } else if s.Shape == "round" { parts = append(parts, "okrągły") } if s.Notes != "" { parts = append(parts, "notatka: "+s.Notes) } if len(parts) == 0 { return "" } return fmt.Sprintf("(%s)", joinParts(parts)) } func joinParts(parts []string) string { out := parts[0] for i := 1; i < len(parts); i++ { out += ", " + parts[i] } return out } type Order struct { ID int Name string Surname string Phone string Location string Date time.Time Accepted time.Time Status string Paid Price // increments of 0.01 Cakes []Cake SpecialCakes []SpecialCake } func (o *Order) Subtotal() Price { var out Price for _, e := range o.Cakes { out += e.Price * Price(e.Amount) } for _, s := range o.SpecialCakes { out += s.Price } return out } func (o *Order) Total() Price { return o.Subtotal() - o.Paid } func (c *Cake) Total() Price { return Price(c.Amount) * c.Price } type OrderCounts struct { Active int DueToday int } type CakeCount struct { ID int Name string Amount int } type BlockedDate struct { ID int Date string }