39 lines
923 B
Go
39 lines
923 B
Go
package routing
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/Teajey/rsvp"
|
|
|
|
lishwist "lishwist/core"
|
|
"lishwist/http/response"
|
|
)
|
|
|
|
func TodoUpdate(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response {
|
|
err := r.ParseForm()
|
|
if err != nil {
|
|
return response.Error(http.StatusBadRequest, "Failed to parse form")
|
|
}
|
|
|
|
switch r.Form.Get("intent") {
|
|
case "unclaim_todo":
|
|
unclaims := r.Form["gift"]
|
|
err := app.ClaimWishes([]string{}, unclaims)
|
|
if err != nil {
|
|
log.Printf("%s\n", err)
|
|
return response.Error(http.StatusInternalServerError, "Failed to update claim...")
|
|
}
|
|
case "complete_todo":
|
|
claims := r.Form["gift"]
|
|
err := app.CompleteWishes(claims)
|
|
if err != nil {
|
|
log.Printf("%s\n", err)
|
|
return response.Error(http.StatusInternalServerError, "Failed to complete gifts...")
|
|
}
|
|
default:
|
|
return response.Error(http.StatusBadRequest, "Invalid intent")
|
|
}
|
|
return rsvp.SeeOther("/")
|
|
}
|