实现Delete接口
This commit is contained in:
@@ -29,6 +29,26 @@ func NewController(feedPlanRepo repository.FeedPlanRepo) *Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete 删除饲料计划
|
||||
func (c *Controller) Delete(ctx *gin.Context) {
|
||||
// 获取路径参数中的计划ID
|
||||
planIDStr := ctx.Param("id")
|
||||
planID, err := strconv.ParseUint(planIDStr, 10, 32)
|
||||
if err != nil {
|
||||
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "无效的计划ID")
|
||||
return
|
||||
}
|
||||
|
||||
// 调用仓库删除计划
|
||||
if err := c.feedPlanRepo.DeleteFeedingPlan(uint(planID)); err != nil {
|
||||
c.logger.Error("删除计划失败: " + err.Error())
|
||||
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "删除计划失败")
|
||||
return
|
||||
}
|
||||
|
||||
controller.SendSuccessResponse(ctx, "删除计划成功", nil)
|
||||
}
|
||||
|
||||
type ListPlansResponse struct {
|
||||
Plans []ListPlanResponseItem `json:"plans"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user