final project structure
This commit is contained in:
28
wagfarm-api/asset/asset.go
Normal file
28
wagfarm-api/asset/asset.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package asset
|
||||
|
||||
import (
|
||||
"wagfarm-api/asset/fertilizer"
|
||||
"wagfarm-api/asset/land"
|
||||
"wagfarm-api/asset/machine"
|
||||
"wagfarm-api/asset/pesticide"
|
||||
"wagfarm-api/asset/plant"
|
||||
"wagfarm-api/asset/product"
|
||||
"wagfarm-api/asset/seed"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const Models []interface{} {
|
||||
|
||||
}
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
group := rg.Group("/asset")
|
||||
fertilizer.RegisterRoutes(group)
|
||||
land.RegisterRoutes(group)
|
||||
machine.RegisterRoutes(group)
|
||||
pesticide.RegisterRoutes(group)
|
||||
plant.RegisterRoutes(group)
|
||||
product.RegisterRoutes(group)
|
||||
seed.RegisterRoutes(group)
|
||||
}
|
||||
30
wagfarm-api/asset/base/model.go
Normal file
30
wagfarm-api/asset/base/model.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package base
|
||||
|
||||
type Asset struct {
|
||||
ID uint `gorm:"primaryKey`
|
||||
Name string `gorm:"not null"`
|
||||
Notes string
|
||||
}
|
||||
|
||||
func (a Asset) GetID() uint { return a.ID }
|
||||
|
||||
type Resource struct {
|
||||
Asset
|
||||
UnitID uint `gorm:"not null"`
|
||||
Unit unit.Unit `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
Cost decimal.Decimal `gorm:"not null; type:decimal(10,2);"` // in euro/unit
|
||||
}
|
||||
|
||||
type BoughtResource struct {
|
||||
Resource
|
||||
BuyDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
||||
BoughtFromID uint `gorm:"not null"`
|
||||
BoughtFrom Seller `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
type SoldResource struct {
|
||||
Resource
|
||||
SaleDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
||||
SoldToID uint `gorm:"not null"`
|
||||
SoldTo Customer `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
}
|
||||
20
wagfarm-api/asset/fertilizer/model.go
Normal file
20
wagfarm-api/asset/fertilizer/model.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package fertilizer
|
||||
|
||||
import "wagfarm-api/asset/base"
|
||||
|
||||
type Fertilizer struct {
|
||||
base.BoughtResource
|
||||
FertilizerTypeID uint `gorm:"not null"`
|
||||
FertilizerType FertilizerType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
// Association to the ingredients. This represents the composition.
|
||||
Ingredients []FertilizerIngredient `gorm:"not null; many2many:fertilizer_ingredient"`
|
||||
}
|
||||
|
||||
type FertilizerIngredient struct {
|
||||
FertilizerAssetID uint `gorm:"primaryKey"` // foreign key to the fertilizer asset
|
||||
IngredientID uint `gorm:"primaryKey"` // foreign key to the ingredient
|
||||
Amount float64 `gorm:"not null"` // amount of the ingredient
|
||||
|
||||
// Preload the ingredient details if needed.
|
||||
Ingredient Ingredient `gorm:"not null"`
|
||||
}
|
||||
11
wagfarm-api/asset/fertilizer/route.go
Normal file
11
wagfarm-api/asset/fertilizer/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package fertilizer
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/fertilizer"), generic.DefaultCRUDController[Fertilizer]())
|
||||
}
|
||||
11
wagfarm-api/asset/land/model.go
Normal file
11
wagfarm-api/asset/land/model.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package land
|
||||
|
||||
import "wagfarm-api/asset/base"
|
||||
|
||||
type Land struct {
|
||||
base.Asset
|
||||
FID string `gorm:"not null"`
|
||||
IsWaterProtectionArea bool `gorm:"not null"`
|
||||
IsRedArea bool `gorm:"not null"`
|
||||
Area float64 `gorm:"not null"`
|
||||
}
|
||||
11
wagfarm-api/asset/land/route.go
Normal file
11
wagfarm-api/asset/land/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package land
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/land"), generic.DefaultCRUDController[Land]())
|
||||
}
|
||||
9
wagfarm-api/asset/machine/model.go
Normal file
9
wagfarm-api/asset/machine/model.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"wagfarm-api/asset/base"
|
||||
)
|
||||
|
||||
type Machine struct {
|
||||
base.Resource
|
||||
}
|
||||
11
wagfarm-api/asset/machine/route.go
Normal file
11
wagfarm-api/asset/machine/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/machine"), generic.DefaultCRUDController[Machine]())
|
||||
}
|
||||
9
wagfarm-api/asset/pesticide/model.go
Normal file
9
wagfarm-api/asset/pesticide/model.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package pesticide
|
||||
|
||||
import "wagfarm-api/asset/base"
|
||||
|
||||
type Pesticide struct {
|
||||
base.BoughtResource
|
||||
PesticideTypeID uint `gorm:"not null"`
|
||||
PesticideType PesticideType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
}
|
||||
11
wagfarm-api/asset/pesticide/route.go
Normal file
11
wagfarm-api/asset/pesticide/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package pesticide
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/pesticide"), generic.DefaultCRUDController[Pesticide]())
|
||||
}
|
||||
18
wagfarm-api/asset/plant/model.go
Normal file
18
wagfarm-api/asset/plant/model.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"wagfarm-api/asset/base"
|
||||
"wagfarm-api/asset/land"
|
||||
)
|
||||
|
||||
type Plant struct {
|
||||
base.Asset
|
||||
LandId uint `gorm:"not null"`
|
||||
Land land.Land `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
CropID uint `gorm:"not null"`
|
||||
Crop crop.Crop `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
CoverCropID uint `gorm:"not null"`
|
||||
CoverCrop crop.Crop `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
Year uint `gorm:"not null"`
|
||||
AreaPercentage float64 `gorm:"not null"`
|
||||
}
|
||||
11
wagfarm-api/asset/plant/route.go
Normal file
11
wagfarm-api/asset/plant/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/plant"), generic.DefaultCRUDController[Plant]())
|
||||
}
|
||||
9
wagfarm-api/asset/product/model.go
Normal file
9
wagfarm-api/asset/product/model.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package product
|
||||
|
||||
import "wagfarm-api/asset/base"
|
||||
|
||||
type Product struct {
|
||||
base.SoldResource
|
||||
ProductTypeID uint `gorm:"not null"`
|
||||
ProductType ProductType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
}
|
||||
11
wagfarm-api/asset/product/route.go
Normal file
11
wagfarm-api/asset/product/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/product"), generic.DefaultCRUDController[Product]())
|
||||
}
|
||||
11
wagfarm-api/asset/seed/model.go
Normal file
11
wagfarm-api/asset/seed/model.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"wagfarm-api/asset/base"
|
||||
)
|
||||
|
||||
type Seed struct {
|
||||
base.BoughtResource
|
||||
SeedTypeID uint `gorm:"not null"`
|
||||
SeedType SeedType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
}
|
||||
11
wagfarm-api/asset/seed/route.go
Normal file
11
wagfarm-api/asset/seed/route.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"wagfarm-api/generic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoutes(rg *gin.RouterGroup) {
|
||||
generic.RegisterCRUDRoutes(rg.Group("/seed"), generic.DefaultCRUDController[Seed]())
|
||||
}
|
||||
Reference in New Issue
Block a user