fixes
This commit is contained in:
1 parent
c8cc0fb28a
commit
e790c02d59
16 files changed
+659
-15
No files matched your search
@@ -222,6 +222,11 @@ func (c *Collector) SetIssueStatus(id, status string) (issues.Issue, bool) {
|
||||
return c.issues.SetStatus(id, status)
|
||||
}
|
||||
|
||||
// SetIssueStatusStore makes resolved/ignored decisions survive restarts.
|
||||
func (c *Collector) SetIssueStatusStore(ctx context.Context, store issues.StatusStore) error {
|
||||
return c.issues.SetStatusStore(ctx, store)
|
||||
}
|
||||
|
||||
func (c *Collector) SimilarIssues(id string, limit int) ([]issues.SimilarIssue, bool) {
|
||||
return c.issues.Similar(id, limit)
|
||||
}
|
||||
|
||||
@@ -116,3 +116,30 @@ func (c *Collector) HandleTodoList(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(items)
|
||||
}
|
||||
|
||||
// HandleTodoUpdate marks a todo done or open: PATCH /api/todos/{id} {"done": bool}.
|
||||
func (c *Collector) HandleTodoUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if c.todoStore == nil {
|
||||
http.Error(w, "todos not enabled", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Done *bool `json:"done"`
|
||||
}
|
||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1024)).Decode(&req); err != nil || req.Done == nil {
|
||||
http.Error(w, "body must be {\"done\": true|false}", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
t, ok, err := c.todoStore.SetDone(r.Context(), r.PathValue("id"), *req.Done)
|
||||
if err != nil {
|
||||
log.Printf("failed to update todo: %v", err)
|
||||
http.Error(w, "failed to update todo", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
http.Error(w, "todo not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(t)
|
||||
}
|
||||
Reference in new issue
Block a user