final project structure

This commit is contained in:
2025-04-15 22:36:22 +02:00
parent d6b3e88b5f
commit 284a40fac2
65 changed files with 668 additions and 447 deletions

View 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)
}

View 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;"`
}

View 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"`
}

View 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]())
}

View 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"`
}

View 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]())
}

View File

@@ -0,0 +1,9 @@
package machine
import (
"wagfarm-api/asset/base"
)
type Machine struct {
base.Resource
}

View 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]())
}

View 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;"`
}

View 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]())
}

View 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"`
}

View 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]())
}

View 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;"`
}

View 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]())
}

View 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;"`
}

View 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]())
}