|
|
|
|
@ -453,6 +453,8 @@ func (a *application) server() (func() error, func() error) {
|
|
|
|
|
mux.HandleFunc("GET /api/audio-proxy", a.handleAudioProxyRequest)
|
|
|
|
|
mux.HandleFunc("POST /api/vikunja/{widgetID}/complete-task", a.handleVikunjaCompleteTask)
|
|
|
|
|
mux.HandleFunc("POST /api/vikunja/{widgetID}/update-task", a.handleVikunjaUpdateTask)
|
|
|
|
|
mux.HandleFunc("POST /api/vikunja/{widgetID}/add-label", a.handleVikunjaAddLabel)
|
|
|
|
|
mux.HandleFunc("POST /api/vikunja/{widgetID}/remove-label", a.handleVikunjaRemoveLabel)
|
|
|
|
|
mux.HandleFunc("GET /api/vikunja/{widgetID}/labels", a.handleVikunjaGetLabels)
|
|
|
|
|
|
|
|
|
|
if a.RequiresAuth {
|
|
|
|
|
@ -587,10 +589,9 @@ func (a *application) handleVikunjaUpdateTask(w http.ResponseWriter, r *http.Req
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request struct {
|
|
|
|
|
TaskID int `json:"task_id"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
DueDate string `json:"due_date"`
|
|
|
|
|
LabelIDs []int `json:"label_ids"`
|
|
|
|
|
TaskID int `json:"task_id"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
DueDate string `json:"due_date"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
|
|
|
|
@ -599,7 +600,95 @@ func (a *application) handleVikunjaUpdateTask(w http.ResponseWriter, r *http.Req
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := vikunjaWidget.updateTask(request.TaskID, request.Title, request.DueDate, request.LabelIDs); err != nil {
|
|
|
|
|
if err := vikunjaWidget.updateTaskBasic(request.TaskID, request.Title, request.DueDate); err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
w.Write([]byte(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
w.Write([]byte(`{"success": true}`))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *application) handleVikunjaAddLabel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
widgetIDStr := r.PathValue("widgetID")
|
|
|
|
|
widgetID, err := strconv.ParseUint(widgetIDStr, 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Invalid widget ID"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget, exists := a.widgetByID[widgetID]
|
|
|
|
|
if !exists {
|
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
w.Write([]byte("Widget not found"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vikunjaWidget, ok := widget.(*vikunjaWidget)
|
|
|
|
|
if !ok {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Widget is not a Vikunja widget"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request struct {
|
|
|
|
|
TaskID int `json:"task_id"`
|
|
|
|
|
LabelID int `json:"label_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Invalid request body"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := vikunjaWidget.addLabelToTask(request.TaskID, request.LabelID); err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
w.Write([]byte(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
w.Write([]byte(`{"success": true}`))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *application) handleVikunjaRemoveLabel(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
widgetIDStr := r.PathValue("widgetID")
|
|
|
|
|
widgetID, err := strconv.ParseUint(widgetIDStr, 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Invalid widget ID"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget, exists := a.widgetByID[widgetID]
|
|
|
|
|
if !exists {
|
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
w.Write([]byte("Widget not found"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vikunjaWidget, ok := widget.(*vikunjaWidget)
|
|
|
|
|
if !ok {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Widget is not a Vikunja widget"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request struct {
|
|
|
|
|
TaskID int `json:"task_id"`
|
|
|
|
|
LabelID int `json:"label_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
w.Write([]byte("Invalid request body"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := vikunjaWidget.removeLabelFromTask(request.TaskID, request.LabelID); err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
w.Write([]byte(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
|