Skip to content

Commit 9dccd14

Browse files
authored
Merge pull request #507 from LydiaCai1203/feat-title-task
feat: task 更新接口
2 parents 0ddd688 + 28f013f commit 9dccd14

File tree

12 files changed

+350
-5
lines changed

12 files changed

+350
-5
lines changed

backend/biz/task/handler/v1/task.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func NewTaskHandler(i *do.Injector) (*TaskHandler, error) {
107107
v1.POST("", web.BindHandler(h.Create))
108108
v1.PUT("/stop", web.BindHandler(h.Stop))
109109
v1.DELETE("/:id", web.BindHandler(h.Delete))
110+
v1.PUT("/:id", web.BindHandler(h.Update))
110111
// 语音识别文字接口
111112
v1.POST("/speech-to-text", web.BaseHandler(h.SpeechToText))
112113

@@ -133,6 +134,27 @@ func (h *TaskHandler) Delete(c *web.Context, req domain.IDReq[uuid.UUID]) error
133134
return c.Success(nil)
134135
}
135136

137+
// Update 更新任务
138+
//
139+
// @Summary 更新任务
140+
// @Description 更新任务信息(如标题)
141+
// @Tags 【用户】任务管理
142+
// @Accept json
143+
// @Produce json
144+
// @Security MonkeyCodeAIAuth
145+
// @Param id path string true "任务 ID"
146+
// @Param param body domain.UpdateTaskReq true "请求参数"
147+
// @Success 200 {object} web.Resp{} "成功"
148+
// @Failure 500 {object} web.Resp "服务器内部错误"
149+
// @Router /api/v1/users/tasks/{id} [put]
150+
func (h *TaskHandler) Update(c *web.Context, req domain.UpdateTaskReq) error {
151+
user := middleware.GetUser(c)
152+
if err := h.usecase.Update(c.Request().Context(), user, req); err != nil {
153+
return err
154+
}
155+
return c.Success(nil)
156+
}
157+
136158
// Stop 停止任务
137159
//
138160
// @Summary 停止任务

backend/biz/task/usecase/task.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,16 @@ func (a *TaskUsecase) getCodingConfigs(cli consts.CliName, m *db.Model, skillIDs
581581
return coding, cfs, nil
582582
}
583583

584+
// Update implements domain.TaskUsecase.
585+
func (a *TaskUsecase) Update(ctx context.Context, user *domain.User, req domain.UpdateTaskReq) error {
586+
return a.repo.Update(ctx, user, req.ID, func(up *db.TaskUpdateOne) error {
587+
if req.Title != nil {
588+
up.SetTitle(*req.Title)
589+
}
590+
return nil
591+
})
592+
}
593+
584594
// Delete implements domain.TaskUsecase.
585595
func (a *TaskUsecase) Delete(ctx context.Context, user *domain.User, id uuid.UUID) error {
586596
t, err := a.repo.Info(ctx, user, id, false)

backend/db/migrate/schema.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/mutation.go

Lines changed: 74 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/runtime/runtime.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/task.go

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/task/task.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/task/where.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)