重构配方类服务层
This commit is contained in:
@@ -15,15 +15,15 @@ import (
|
||||
|
||||
// NutrientController 定义了营养种类相关的控制器
|
||||
type NutrientController struct {
|
||||
ctx context.Context
|
||||
feedManagementService service.FeedManagementService
|
||||
ctx context.Context
|
||||
nutrientService service.NutrientService
|
||||
}
|
||||
|
||||
// NewNutrientController 创建一个新的 NutrientController 实例
|
||||
func NewNutrientController(ctx context.Context, feedManagementService service.FeedManagementService) *NutrientController {
|
||||
func NewNutrientController(ctx context.Context, feedManagementService service.NutrientService) *NutrientController {
|
||||
return &NutrientController{
|
||||
ctx: ctx,
|
||||
feedManagementService: feedManagementService,
|
||||
ctx: ctx,
|
||||
nutrientService: feedManagementService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (c *NutrientController) CreateNutrient(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体: "+err.Error(), actionType, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
resp, err := c.feedManagementService.CreateNutrient(reqCtx, &req)
|
||||
resp, err := c.nutrientService.CreateNutrient(reqCtx, &req)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层创建营养种类失败: %v", actionType, err)
|
||||
if errors.Is(err, service.ErrNutrientNameConflict) {
|
||||
@@ -86,7 +86,7 @@ func (c *NutrientController) UpdateNutrient(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体: "+err.Error(), actionType, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
resp, err := c.feedManagementService.UpdateNutrient(reqCtx, uint32(id), &req)
|
||||
resp, err := c.nutrientService.UpdateNutrient(reqCtx, uint32(id), &req)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层更新营养种类失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, service.ErrNutrientNotFound) {
|
||||
@@ -121,7 +121,7 @@ func (c *NutrientController) DeleteNutrient(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的营养种类ID格式", actionType, "营养种类ID格式错误", idStr)
|
||||
}
|
||||
|
||||
err = c.feedManagementService.DeleteNutrient(reqCtx, uint32(id))
|
||||
err = c.nutrientService.DeleteNutrient(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层删除营养种类失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, service.ErrNutrientNotFound) {
|
||||
@@ -153,7 +153,7 @@ func (c *NutrientController) GetNutrient(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的营养种类ID格式", actionType, "营养种类ID格式错误", idStr)
|
||||
}
|
||||
|
||||
resp, err := c.feedManagementService.GetNutrient(reqCtx, uint32(id))
|
||||
resp, err := c.nutrientService.GetNutrient(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层获取营养种类详情失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, service.ErrNutrientNotFound) {
|
||||
@@ -184,7 +184,7 @@ func (c *NutrientController) ListNutrients(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "查询参数绑定失败", req)
|
||||
}
|
||||
|
||||
resp, err := c.feedManagementService.ListNutrients(reqCtx, &req)
|
||||
resp, err := c.nutrientService.ListNutrients(reqCtx, &req)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层获取营养种类列表失败: %v", actionType, err)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取营养种类列表失败: "+err.Error(), actionType, "服务层获取营养种类列表失败", nil)
|
||||
|
||||
Reference in New Issue
Block a user