cake-order-tracker/models/order.go
2025-07-07 11:30:28 +02:00

41 lines
670 B
Go

package models
import (
"time"
"gorm.io/gorm"
)
// money amounts are in incremetns of 0.01
type OrderItem struct {
Product Product
Amount uint
ProductID uint `gorm:"primaryKey;autoIncrement:false"`
OrderID uint `gorm:"primaryKey;autoIncrement:false"`
}
type Order struct {
gorm.Model
Name string
Surname string
Phone string
Location string
Status string
Prepaid uint
Date time.Time
OrderItems []OrderItem
}
func (c *OrderItem) Total() uint {
return c.Amount * c.Product.Price
}
func (o *Order) Total() uint {
var out uint
for _, e := range o.OrderItems {
out += e.Total()
}
out -= o.Prepaid
return out
}