38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
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"`
|
|
}
|