kleinTodo/server/handler/updateHandler.go
Darius klein 7cf6eabbdd
All checks were successful
build and deploy kleinTodo / build (push) Successful in 51s
build and deploy kleinTodo / build (release) Successful in 1m24s
ci: add integration tests and pipeline step
Co-authored-by: Junie <junie@jetbrains.com>
2026-04-04 13:55:37 +02:00

35 lines
800 B
Go

package handler
import (
"encoding/json"
"net/http"
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common"
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common/jwt"
)
func UpdateHandler(w http.ResponseWriter, r *http.Request) {
// 1. Setup: Auth, Decode, Database Connection
user, err := jwt.GetVerifiedUser(r)
if handleError(w, http.StatusUnauthorized, err) {
return
}
var todo common.Todo
if handleError(w, http.StatusBadRequest, json.NewDecoder(r.Body).Decode(&todo)) {
return
}
store, err := common.GetServerDataStore()
if handleError(w, http.StatusInternalServerError, err) {
return
}
// 2. Store the todo (it updates LastModified in the Store method)
if handleError(w, http.StatusInternalServerError, todo.Store(store, user)) {
return
}
w.WriteHeader(http.StatusOK)
}