Version: 0.6.8.dev.260317

- 🧹 删除 `docs/apifox` 目录,接口契约统一迁移并维护于 Apifox 云端
-  新增“取消任务完成状态”接口
This commit is contained in:
Losita
2026-03-17 22:54:07 +08:00
parent 5223b5db61
commit cd95aeeaaa
7 changed files with 169 additions and 110 deletions

View File

@@ -95,3 +95,36 @@ func (th *TaskHandler) CompleteTask(c *gin.Context) {
// 5. 返回统一响应结构。
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
}
// UndoCompleteTask 取消任务“已完成”勾选。
//
// 职责边界:
// 1. 负责解析请求与读取 user_id
// 2. 负责调用 Service 执行业务恢复;
// 3. 不负责“任务是否已完成”的业务判断(由 Service/DAO 负责)。
func (th *TaskHandler) UndoCompleteTask(c *gin.Context) {
// 1. 绑定请求参数。
var req model.UserUndoCompleteTaskRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, respond.WrongParamType)
fmt.Println(err)
return
}
// 2. 从鉴权上下文读取 user_id保证只操作当前用户任务。
userID := c.GetInt("user_id")
// 3. 设置短超时,避免该写接口占用连接过久。
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
defer cancel()
// 4. 调用 Service 执行“取消已完成勾选”逻辑。
resp, err := th.svc.UndoCompleteTask(ctx, &req, userID)
if err != nil {
respond.DealWithError(c, err)
return
}
// 5. 返回统一响应结构。
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
}