final project structure
This commit is contained in:
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]())
|
||||
}
|
||||
Reference in New Issue
Block a user