ingredient composition

This commit is contained in:
Efril
2026-04-27 21:17:12 +07:00
parent 3542104050
commit a7022dd4c1
20 changed files with 759 additions and 798 deletions
+31 -24
View File
@@ -26,15 +26,23 @@ type Ingredient struct {
}
type CreateIngredientRequest struct {
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
Name string `json:"name" validate:"required,min=1,max=255"`
UnitID uuid.UUID `json:"unit_id" validate:"required"`
Cost float64 `json:"cost" validate:"min=0"`
Stock float64 `json:"stock" validate:"min=0"`
IsSemiFinished bool `json:"is_semi_finished"`
IsActive bool `json:"is_active"`
Metadata entities.Metadata `json:"metadata"`
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
Name string `json:"name" validate:"required,min=1,max=255"`
UnitID uuid.UUID `json:"unit_id" validate:"required"`
Cost float64 `json:"cost" validate:"min=0"`
Stock float64 `json:"stock" validate:"min=0"`
IsSemiFinished bool `json:"is_semi_finished"`
IsActive bool `json:"is_active"`
Metadata entities.Metadata `json:"metadata"`
Compositions []CompositionItemRequest `json:"compositions,omitempty"`
}
// CompositionItemRequest is used inside create ingredient request.
type CompositionItemRequest struct {
ChildIngredientID uuid.UUID `json:"child_ingredient_id" validate:"required"`
Quantity float64 `json:"quantity" validate:"required,gt=0"`
OutletID *uuid.UUID `json:"outlet_id"`
}
type UpdateIngredientRequest struct {
@@ -49,19 +57,18 @@ type UpdateIngredientRequest struct {
}
type IngredientResponse struct {
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
Name string `json:"name"`
UnitID uuid.UUID `json:"unit_id"`
Cost float64 `json:"cost"`
Stock float64 `json:"stock"`
IsSemiFinished bool `json:"is_semi_finished"`
IsActive bool `json:"is_active"`
Metadata entities.Metadata `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Relations
Unit *Unit `json:"unit,omitempty"`
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
Name string `json:"name"`
UnitID uuid.UUID `json:"unit_id"`
Cost float64 `json:"cost"`
Stock float64 `json:"stock"`
IsSemiFinished bool `json:"is_semi_finished"`
IsActive bool `json:"is_active"`
Metadata entities.Metadata `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Unit *Unit `json:"unit,omitempty"`
Compositions []*IngredientCompositionResponse `json:"compositions,omitempty"`
}
+22 -33
View File
@@ -6,44 +6,33 @@ import (
"github.com/google/uuid"
)
type IngredientComposition struct {
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
ParentIngredientID uuid.UUID `json:"parent_ingredient_id"`
ChildIngredientID uuid.UUID `json:"child_ingredient_id"`
Quantity float64 `json:"quantity"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Relations
ParentIngredient *Ingredient `json:"parent_ingredient,omitempty"`
ChildIngredient *Ingredient `json:"child_ingredient,omitempty"`
}
type CreateIngredientCompositionRequest struct {
OutletID *uuid.UUID `json:"outlet_id"`
ParentIngredientID uuid.UUID `json:"parent_ingredient_id" validate:"required"`
ChildIngredientID uuid.UUID `json:"child_ingredient_id" validate:"required"`
Quantity float64 `json:"quantity" validate:"required,gt=0"`
}
type UpdateIngredientCompositionRequest struct {
OutletID *uuid.UUID `json:"outlet_id"`
Quantity float64 `json:"quantity" validate:"required,gt=0"`
}
type IngredientCompositionResponse struct {
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
OutletID *uuid.UUID `json:"outlet_id"`
ParentIngredientID uuid.UUID `json:"parent_ingredient_id"`
ChildIngredientID uuid.UUID `json:"child_ingredient_id"`
Quantity float64 `json:"quantity"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID uuid.UUID `json:"id"`
OutletID *uuid.UUID `json:"outlet_id"`
ChildIngredientID uuid.UUID `json:"child_ingredient_id"`
Quantity float64 `json:"quantity"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ChildIngredient *IngredientResponse `json:"child_ingredient,omitempty"`
ParentIngredient *IngredientResponse `json:"parent_ingredient,omitempty"`
}
// Relations
ParentIngredient *Ingredient `json:"parent_ingredient,omitempty"`
ChildIngredient *Ingredient `json:"child_ingredient,omitempty"`
type CompositionItem struct {
ChildIngredientID uuid.UUID `json:"child_ingredient_id" validate:"required"`
Quantity float64 `json:"quantity" validate:"required,gt=0"`
OutletID *uuid.UUID `json:"outlet_id"`
}
type AddIngredientCompositionsRequest struct {
Compositions []CompositionItem `json:"compositions" validate:"required,min=1,dive"`
}
type AddIngredientCompositionsResponse struct {
ParentIngredient *IngredientResponse `json:"parent_ingredient"`
Compositions []*IngredientCompositionResponse `json:"compositions"`
}