final project structure
This commit is contained in:
31
wagfarm-api/log/base/model.go
Normal file
31
wagfarm-api/log/base/model.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package base
|
||||
|
||||
import "time"
|
||||
|
||||
type BaseLog struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Name string `gorm:"not null"`
|
||||
Notes string `gorm:"not null"`
|
||||
LogType string `gorm:"not null"`
|
||||
Date time.Time `gorm:"default:CURRENT_TIME"`
|
||||
Duration float64 `gorm:"not null"` // in hours
|
||||
VisibiltyID uint `gorm:"not null"`
|
||||
Visibility taxonomy.Visibility `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
|
||||
func (l BaseLog) GetID() uint { return l.ID }
|
||||
|
||||
type ExtendedLog struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
LogID uint `gorm:"not null"`
|
||||
BaseLog BaseLog `gorm:"foreignKey:LogID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
|
||||
func (l ExtendedLog) GetID() uint { return l.ID }
|
||||
|
||||
type FieldWorkLog struct {
|
||||
ExtendedLog
|
||||
WorkedAreaPercentage float64 `gorm:"not null"`
|
||||
MachineID uint `gorm:"not null"`
|
||||
Machine asset.Machine `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
11
wagfarm-api/log/base/route.go
Normal file
11
wagfarm-api/log/base/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg, generic.DefaultCRUDController[BaseLog]())
|
||||
}
|
||||
12
wagfarm-api/log/cropprotection/model.go
Normal file
12
wagfarm-api/log/cropprotection/model.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package cropprotection
|
||||
|
||||
import "wagfarm-api/log/base"
|
||||
|
||||
type CropProtectionLog struct {
|
||||
base.FieldWorkLog
|
||||
PesticideID uint `gorm:"not null"`
|
||||
Pesticide taxonomy.Pesticide `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
Amount float64 `gorm:"not null"` // in units of the pesticide
|
||||
PerformedByID uint `gorm:"not null"`
|
||||
PerformedBy taxonomy.Worker `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
11
wagfarm-api/log/cropprotection/route.go
Normal file
11
wagfarm-api/log/cropprotection/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package cropprotection
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/cropprotection"), generic.DefaultCRUDController[CropProtectionLog]())
|
||||
}
|
||||
12
wagfarm-api/log/fertilizing/model.go
Normal file
12
wagfarm-api/log/fertilizing/model.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package fertilizing
|
||||
|
||||
import (
|
||||
"wagfarm-api/log/base"
|
||||
)
|
||||
|
||||
type FertilizingLog struct {
|
||||
base.ExtendedLog
|
||||
FertilizerID uint `gorm:"not null"`
|
||||
Fertilizer asset.Fertilizer `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
Amount float64 `gorm:"not null"` // in units of the fertilizer
|
||||
}
|
||||
11
wagfarm-api/log/fertilizing/route.go
Normal file
11
wagfarm-api/log/fertilizing/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package fertilizing
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/fertilizer"), generic.DefaultCRUDController[FertilizingLog]())
|
||||
}
|
||||
9
wagfarm-api/log/harvest/model.go
Normal file
9
wagfarm-api/log/harvest/model.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package harvest
|
||||
|
||||
import base "wagfarm-api/log/seeding"
|
||||
|
||||
type HarvestLog struct {
|
||||
base.FieldWorkLog
|
||||
Product asset.Product `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
Amount float64 `gorm:"not null"` // in units of the product
|
||||
}
|
||||
11
wagfarm-api/log/harvest/route.go
Normal file
11
wagfarm-api/log/harvest/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package harvest
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/harvest"), generic.DefaultCRUDController[HarvestLog]())
|
||||
}
|
||||
14
wagfarm-api/log/seeding/model.go
Normal file
14
wagfarm-api/log/seeding/model.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package seeding
|
||||
|
||||
import "wagfarm-api/log/base"
|
||||
|
||||
type SeedingLog struct {
|
||||
base.FieldWorkLog
|
||||
SeedID uint `gorm:"not null"`
|
||||
Seed asset.Seed `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
TechniqueID uint `gorm:"not null"`
|
||||
Technique taxonomy.SeedingTechnique `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
Amount float64 `gorm:"not null"` // in units/ha
|
||||
ConditionsID uint `gorm:"not null"`
|
||||
Conditions taxonomy.SeedingCondition `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||
}
|
||||
11
wagfarm-api/log/seeding/route.go
Normal file
11
wagfarm-api/log/seeding/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package seeding
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/seeding"), generic.DefaultCRUDController[SeedingLog]())
|
||||
}
|
||||
Reference in New Issue
Block a user