1. 实现前端删除饲喂计划

2. 修复后端delete接口bug
This commit is contained in:
2025-09-10 16:25:52 +08:00
parent 40a19b831a
commit cc7ea94e41
5 changed files with 18 additions and 15 deletions

View File

@@ -126,15 +126,17 @@ func (c *Controller) convertToCreateModel(req *CreateRequest) *model.FeedingPlan
// 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")
var req struct {
ID uint `json:"id" binding:"required"`
}
if err := ctx.ShouldBindJSON(&req); err != nil {
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "请求参数错误: "+err.Error())
return
}
// 调用仓库删除计划
if err := c.feedPlanRepo.DeleteFeedingPlan(uint(planID)); err != nil {
if err := c.feedPlanRepo.DeleteFeedingPlan(uint(req.ID)); err != nil {
c.logger.Error("删除计划失败: " + err.Error())
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "删除计划失败")
return