Files
pages/internal/server/task_focus.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

55 lines
1.5 KiB
Go

package server
import (
"encoding/json"
"net/http"
"time"
"pageswiki/internal/store"
)
func (s *Server) handleTaskFocus(w http.ResponseWriter, r *http.Request, actor string, active bool, parts []string) {
if len(parts) != 1 {
http.NotFound(w, r)
return
}
domain := s.domainUUIDForRequest(r)
if r.Method == "GET" {
f, err := s.store.LatestTaskFocus(r.Context(), domain, actor)
if err != nil {
taskError(w, err)
return
}
writeEventJSON(w, 200, map[string]any{"item": f, "server_now_ms": time.Now().UnixMilli()})
return
}
if r.Method != "POST" {
w.WriteHeader(405)
return
}
if !active {
taskError(w, store.ErrAccessDenied)
return
}
var input struct {
UUID string `json:"uuid"`
TaskUUID string `json:"task_uuid"`
Phase string `json:"phase"`
Minutes int64 `json:"minutes"`
Action string `json:"action"`
Version int64 `json:"version"`
}
dec := json.NewDecoder(http.MaxBytesReader(w, r.Body, 4096))
dec.DisallowUnknownFields()
if err := dec.Decode(&input); err != nil || input.Minutes < 0 || input.Minutes > 180 {
taskError(w, store.ErrTaskInvalid)
return
}
f, err := s.store.ChangeTaskFocus(r.Context(), domain, actor, input.Action, store.TaskFocus{UUID: input.UUID, TaskUUID: input.TaskUUID, Phase: input.Phase, DurationMS: input.Minutes * 60000}, input.Version, time.Now())
if err != nil {
taskError(w, err)
return
}
writeEventJSON(w, 200, map[string]any{"item": f, "server_now_ms": time.Now().UnixMilli()})
}