moved to gorm

This commit is contained in:
Bronku 2025-07-07 11:30:28 +02:00
parent 66884c64bb
commit a074f264df
30 changed files with 247 additions and 1040 deletions

41
models/order.go Normal file
View file

@ -0,0 +1,41 @@
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
}