实现 DeletePlan 和单测

This commit is contained in:
2025-09-14 17:02:36 +08:00
parent 164c7a4923
commit f11bd35b74
2 changed files with 122 additions and 4 deletions

View File

@@ -235,9 +235,23 @@ func (c *Controller) UpdatePlan(ctx *gin.Context) {
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id} [delete]
func (c *Controller) DeletePlan(ctx *gin.Context) {
// 占位符:此处应调用服务层或仓库层来删除计划
c.logger.Infof("收到删除计划请求 (占位符)")
controller.SendResponse(ctx, controller.CodeSuccess, "删除计划接口占位符", nil)
// 1. 从 URL 路径中获取 ID
idStr := ctx.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
controller.SendErrorResponse(ctx, controller.CodeBadRequest, "无效的计划ID格式")
return
}
// 2. 调用仓库层删除计划
if err := c.planRepo.DeletePlan(uint(id)); err != nil {
c.logger.Errorf("删除计划失败: %v", err)
controller.SendErrorResponse(ctx, controller.CodeInternalError, "删除计划时发生内部错误")
return
}
// 3. 发送成功响应
controller.SendResponse(ctx, controller.CodeSuccess, "计划删除成功", nil)
}
// StartPlan godoc