MCPcopy Create free account
hub / github.com/krau/SaveAny-Bot / CreateTaskHandler

Method CreateTaskHandler

api/handlers.go:25–56  ·  view source on GitHub ↗

CreateTaskHandler 创建任务处理器

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

23
24// CreateTaskHandler 创建任务处理器
25func (h *Handlers) CreateTaskHandler(w http.ResponseWriter, r *http.Request) {
26 if r.Method != http.MethodPost {
27 WriteError(w, http.StatusMethodNotAllowed, "method_not_allowed", "only POST method is allowed")
28 return
29 }
30
31 var req CreateTaskRequest
32 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
33 WriteError(w, http.StatusBadRequest, "invalid_request", "failed to decode request body: "+err.Error())
34 return
35 }
36
37 // 验证请求
38 if req.Type == "" {
39 WriteError(w, http.StatusBadRequest, "invalid_request", "task type is required")
40 return
41 }
42
43 if req.Storage == "" {
44 WriteError(w, http.StatusBadRequest, "invalid_request", "storage is required")
45 return
46 }
47
48 // 创建任务
49 resp, err := h.factory.CreateTask(&req)
50 if err != nil {
51 WriteError(w, http.StatusBadRequest, "task_creation_failed", err.Error())
52 return
53 }
54
55 WriteJSON(w, http.StatusCreated, resp)
56}
57
58// ListTasksHandler 列出任务处理器
59func (h *Handlers) ListTasksHandler(w http.ResponseWriter, r *http.Request) {

Callers 3

NewServerFunction · 0.95
TestCreateTaskHandlerFunction · 0.80
TestEdgeCasesFunction · 0.80

Calls 4

WriteErrorFunction · 0.85
WriteJSONFunction · 0.85
CreateTaskMethod · 0.80
ErrorMethod · 0.45

Tested by 2

TestCreateTaskHandlerFunction · 0.64
TestEdgeCasesFunction · 0.64