配方增删改查服务层和控制器
This commit is contained in:
@@ -274,3 +274,49 @@ type PigNutrientRequirementItem struct {
|
||||
MinRequirement float32 `json:"min_requirement" validate:"gte=0"` // 最低营养需求量
|
||||
MaxRequirement float32 `json:"max_requirement" validate:"gte=0"` // 最高营养需求量
|
||||
}
|
||||
|
||||
// =============================================================================================================
|
||||
// 配方 (Recipe) 相关 DTO
|
||||
// =============================================================================================================
|
||||
|
||||
// RecipeIngredientDto 代表配方中的一个原料及其百分比
|
||||
type RecipeIngredientDto struct {
|
||||
RawMaterialID uint32 `json:"raw_material_id" validate:"required"` // 原料ID
|
||||
Percentage float32 `json:"percentage" validate:"gte=0,lte=1"` // 原料在配方中的百分比 (0-1之间)
|
||||
}
|
||||
|
||||
// CreateRecipeRequest 创建配方的请求体
|
||||
type CreateRecipeRequest struct {
|
||||
Name string `json:"name" validate:"required,max=100"` // 配方名称
|
||||
Description string `json:"description" validate:"max=255"` // 配方描述
|
||||
RecipeIngredients []RecipeIngredientDto `json:"recipe_ingredients" validate:"dive"` // 配方原料组成
|
||||
}
|
||||
|
||||
// UpdateRecipeRequest 更新配方的请求体
|
||||
type UpdateRecipeRequest struct {
|
||||
Name string `json:"name" validate:"required,max=100"` // 配方名称
|
||||
Description string `json:"description" validate:"max=255"` // 配方描述
|
||||
RecipeIngredients []RecipeIngredientDto `json:"recipe_ingredients" validate:"dive"` // 配方原料组成
|
||||
}
|
||||
|
||||
// RecipeResponse 配方响应体
|
||||
type RecipeResponse struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
RecipeIngredients []RecipeIngredientDto `json:"recipe_ingredients"`
|
||||
}
|
||||
|
||||
// ListRecipeRequest 定义了获取配方列表的请求参数
|
||||
type ListRecipeRequest struct {
|
||||
Page int `json:"page" query:"page"` // 页码
|
||||
PageSize int `json:"page_size" query:"page_size"` // 每页数量
|
||||
Name *string `json:"name" query:"name"` // 按名称模糊查询
|
||||
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
|
||||
}
|
||||
|
||||
// ListRecipeResponse 是获取配方列表的响应结构
|
||||
type ListRecipeResponse struct {
|
||||
List []RecipeResponse `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user