Unify active task loading across API handlers

This commit is contained in:
Ian Gulliver
2026-10-20 23:31:16 -07:00
parent 74de15db8e
commit 73689f0f2d
5 changed files with 25 additions and 41 deletions
+16 -10
View File
@@ -477,7 +477,7 @@ func (s *Server) GetTask(w http.ResponseWriter, r *http.Request, taskID string)
}
func (s *Server) GetUnmerged(w http.ResponseWriter, r *http.Request, taskID string) {
t, p, ok := s.activeTask(w, r, taskID)
t, p, ok := s.activeTaskProject(w, r, taskID)
if !ok {
return
}
@@ -517,7 +517,7 @@ func (s *Server) MergeTask(w http.ResponseWriter, r *http.Request, taskID string
return
}
t, p, ok := s.activeTask(w, r, taskID)
t, p, ok := s.activeTaskProject(w, r, taskID)
if !ok {
return
}
@@ -621,7 +621,7 @@ func (s *Server) DismissReady(w http.ResponseWriter, r *http.Request, taskID str
}
func (s *Server) MergeIn(w http.ResponseWriter, r *http.Request, taskID string) {
t, p, ok := s.activeTask(w, r, taskID)
t, p, ok := s.activeTaskProject(w, r, taskID)
if !ok {
return
}
@@ -641,7 +641,7 @@ func (s *Server) MergeIn(w http.ResponseWriter, r *http.Request, taskID string)
}
func (s *Server) DiscardTask(w http.ResponseWriter, r *http.Request, taskID string) {
t, _, ok := s.activeTask(w, r, taskID)
t, ok := s.activeTask(w, r, taskID)
if !ok {
return
}
@@ -659,7 +659,7 @@ func (s *Server) PostToBoard(w http.ResponseWriter, r *http.Request, taskID stri
if !readJSON(w, r, &req) {
return
}
t, _, ok := s.activeTask(w, r, taskID)
t, ok := s.activeTask(w, r, taskID)
if !ok {
return
}
@@ -672,18 +672,24 @@ func (s *Server) PostToBoard(w http.ResponseWriter, r *http.Request, taskID stri
w.WriteHeader(http.StatusNoContent)
}
func (s *Server) activeTask(w http.ResponseWriter, r *http.Request, taskID string) (api.Task, api.Project, bool) {
func (s *Server) activeTask(w http.ResponseWriter, r *http.Request, taskID string) (api.Task, bool) {
t, err := s.store.GetTask(r.Context(), taskID)
if err != nil {
writeStoreError(w, err)
return t, api.Project{}, false
return t, false
}
if t.Status != api.TaskStatusActive {
writeError(w, http.StatusConflict, fmt.Errorf("task %s is %s", t.Id, t.Status))
return t, false
}
return t, true
}
func (s *Server) activeTaskProject(w http.ResponseWriter, r *http.Request, taskID string) (api.Task, api.Project, bool) {
t, ok := s.activeTask(w, r, taskID)
if !ok {
return t, api.Project{}, false
}
p, err := s.store.GetProject(r.Context(), t.ProjectId)
if err != nil {
writeStoreError(w, err)
@@ -826,7 +832,7 @@ func (s *Server) ListPreviews(w http.ResponseWriter, r *http.Request, taskID str
}
func (s *Server) ForkSnapshot(w http.ResponseWriter, r *http.Request, taskID string, n int) {
t, p, ok := s.activeTask(w, r, taskID)
t, p, ok := s.activeTaskProject(w, r, taskID)
if !ok {
return
}