任务2.3

This commit is contained in:
2025-10-31 16:11:12 +08:00
parent d22ddac9cd
commit b44e1a0e7c
4 changed files with 165 additions and 83 deletions

View File

@@ -53,12 +53,7 @@ func (c *PigFarmController) CreatePigHouse(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "创建猪舍失败", action, "业务逻辑失败", req)
}
resp := dto.PigHouseResponse{
ID: house.ID,
Name: house.Name,
Description: house.Description,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeCreated, "创建成功", resp, action, "创建成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeCreated, "创建成功", house, action, "创建成功", house)
}
// GetPigHouse godoc
@@ -86,12 +81,7 @@ func (c *PigFarmController) GetPigHouse(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取猪舍失败", action, "业务逻辑失败", id)
}
resp := dto.PigHouseResponse{
ID: house.ID,
Name: house.Name,
Description: house.Description,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取成功", resp, action, "获取成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取成功", house, action, "获取成功", house)
}
// ListPigHouses godoc
@@ -110,16 +100,7 @@ func (c *PigFarmController) ListPigHouses(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取列表失败", action, "业务逻辑失败", nil)
}
var resp []dto.PigHouseResponse
for _, house := range houses {
resp = append(resp, dto.PigHouseResponse{
ID: house.ID,
Name: house.Name,
Description: house.Description,
})
}
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取成功", resp, action, "获取成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取成功", houses, action, "获取成功", houses)
}
// UpdatePigHouse godoc
@@ -154,12 +135,7 @@ func (c *PigFarmController) UpdatePigHouse(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "更新失败", action, "业务逻辑失败", req)
}
resp := dto.PigHouseResponse{
ID: house.ID,
Name: house.Name,
Description: house.Description,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", resp, action, "更新成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", house, action, "更新成功", house)
}
// DeletePigHouse godoc
@@ -222,14 +198,7 @@ func (c *PigFarmController) CreatePen(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "创建猪栏失败", action, "业务逻辑失败", req)
}
resp := dto.PenResponse{
ID: pen.ID,
PenNumber: pen.PenNumber,
HouseID: pen.HouseID,
Capacity: pen.Capacity,
Status: pen.Status,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeCreated, "创建成功", resp, action, "创建成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeCreated, "创建成功", pen, action, "创建成功", pen)
}
// GetPen godoc
@@ -312,15 +281,7 @@ func (c *PigFarmController) UpdatePen(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "更新失败", action, "业务逻辑失败", req)
}
resp := dto.PenResponse{
ID: pen.ID,
PenNumber: pen.PenNumber,
HouseID: pen.HouseID,
Capacity: pen.Capacity,
Status: pen.Status,
PigBatchID: pen.PigBatchID,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", resp, action, "更新成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", pen, action, "更新成功", pen)
}
// DeletePen godoc
@@ -388,13 +349,5 @@ func (c *PigFarmController) UpdatePenStatus(ctx echo.Context) error {
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "更新猪栏状态失败", action, err.Error(), id)
}
resp := dto.PenResponse{
ID: pen.ID,
PenNumber: pen.PenNumber,
HouseID: pen.HouseID,
Capacity: pen.Capacity,
Status: pen.Status,
PigBatchID: pen.PigBatchID,
}
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", resp, action, "更新成功", resp)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "更新成功", pen, action, "更新成功", pen)
}