change log api to reflect data split into base and extension
This commit is contained in:
37
wagfarm-api/logs/generic/model.go
Normal file
37
wagfarm-api/logs/generic/model.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"wagfarm-api/assets/machine"
|
||||
"wagfarm-api/generic"
|
||||
"wagfarm-api/logs/base"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ExtendedLog interface {
|
||||
generic.Model
|
||||
GetBaseLog() base.BaseLog
|
||||
}
|
||||
|
||||
type BaseExtendedLog struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
BaseLogID uint `gorm:"not null"`
|
||||
BaseLog base.BaseLog `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
|
||||
func (l BaseExtendedLog) GetID() uint { return l.ID }
|
||||
func (l BaseExtendedLog) GetBaseLog() base.BaseLog { return l.BaseLog }
|
||||
func (l *BaseExtendedLog) UpdateCost(db *gorm.DB, newCost decimal.Decimal) (err error) {
|
||||
err = db.Model(&base.BaseLog{}).
|
||||
Where("id = ?", l.BaseLogID).
|
||||
Update("cost", newCost).Error
|
||||
return
|
||||
}
|
||||
|
||||
type FieldWorkLog struct {
|
||||
BaseExtendedLog
|
||||
WorkedAreaPercentage float64 `gorm:"not null"`
|
||||
MachineID uint `gorm:"not null"`
|
||||
Machine machine.Machine `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
Reference in New Issue
Block a user