change log api to reflect data split into base and extension

This commit is contained in:
2025-04-24 15:48:21 +02:00
parent c07aa09dcd
commit 2e01287a71
13 changed files with 182 additions and 42 deletions

View File

@@ -2,12 +2,10 @@ package base
import (
"time"
"wagfarm-api/assets/machine"
"wagfarm-api/database"
"wagfarm-api/taxonomy/visibility"
"github.com/shopspring/decimal"
"gorm.io/gorm"
)
type BaseLog struct {
@@ -23,26 +21,4 @@ type BaseLog struct {
}
func (l BaseLog) GetID() uint { return l.ID }
type ExtendedLog struct {
ID uint `gorm:"primaryKey"`
BaseLogID uint `gorm:"not null"`
BaseLog BaseLog `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
}
func (l ExtendedLog) GetID() uint { return l.ID }
func (l *ExtendedLog) UpdateCost(db *gorm.DB, newCost decimal.Decimal) (err error) {
err = db.Model(&BaseLog{}).
Where("id = ?", l.BaseLogID).
Update("cost", newCost).Error
return
}
type FieldWorkLog struct {
ExtendedLog
WorkedAreaPercentage float64 `gorm:"not null"`
MachineID uint `gorm:"not null"`
Machine machine.Machine `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
}
func RegisterModels() { database.RegisterModel(&BaseLog{}) }
func RegisterModels() { database.RegisterModel(&BaseLog{}) }

View File

@@ -7,5 +7,5 @@ import (
)
func RegisterRoutes(rg *gin.RouterGroup) {
generic.RegisterCRUDRoutes(rg, generic.DefaultCRUDController[BaseLog]())
generic.RegisterRRoutes(rg, generic.DefaultRController[BaseLog]())
}