lishwist/server/routing/todo.go

30 lines
747 B
Go

package routing
import (
"lishwist/db"
"lishwist/rsvp"
"net/http"
)
func TodoUpdate(currentUser *db.User, h http.Header, r *rsvp.Request) rsvp.Response {
form := r.ParseForm()
switch form.Get("intent") {
case "unclaim_todo":
unclaims := form["gift"]
err := currentUser.ClaimGifts([]string{}, unclaims)
if err != nil {
return rsvp.Error(http.StatusInternalServerError, "Failed to update claim...").LogError(err)
}
case "complete_todo":
claims := form["gift"]
err := currentUser.CompleteGifts(claims)
if err != nil {
return rsvp.Error(http.StatusInternalServerError, "Failed to complete gifts...").LogError(err)
}
default:
return rsvp.Error(http.StatusBadRequest, "Invalid intent")
}
return rsvp.SeeOther("/")
}