- Add missing bcc argument to NewEmail call in pkg/email/fetch.go - Upgrade github.com/a-h/templ from v0.3.833 to v0.3.1020 to match generator - Add player management routes (add/delete/edit) and playershandler - Update templates and loaddata with pending changes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
86 lines
2 KiB
Go
86 lines
2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hculpan/areweplaying/pkg/data"
|
|
)
|
|
|
|
func addPlayerHandler(w http.ResponseWriter, r *http.Request) {
|
|
if !ValidateJWTFromCookie(r, appKey) {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
r.ParseForm()
|
|
session, err := data.ReadSessionData()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
p := data.Player{
|
|
Name: r.FormValue("name"),
|
|
Email: r.FormValue("email"),
|
|
Gm: r.FormValue("gm") == "on",
|
|
Attending: "unknown",
|
|
}
|
|
|
|
if err := data.AddPlayer(session, p); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/setup", http.StatusSeeOther)
|
|
}
|
|
|
|
func deletePlayerHandler(w http.ResponseWriter, r *http.Request) {
|
|
if !ValidateJWTFromCookie(r, appKey) {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
r.ParseForm()
|
|
session, err := data.ReadSessionData()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
name := r.FormValue("name")
|
|
if err := data.DeletePlayer(session, name); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/setup", http.StatusSeeOther)
|
|
}
|
|
|
|
func editPlayerHandler(w http.ResponseWriter, r *http.Request) {
|
|
if !ValidateJWTFromCookie(r, appKey) {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
r.ParseForm()
|
|
session, err := data.ReadSessionData()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
originalName := r.FormValue("originalName")
|
|
updated := data.Player{
|
|
Name: r.FormValue("name"),
|
|
Email: r.FormValue("email"),
|
|
Gm: r.FormValue("gm") == "on",
|
|
Attending: r.FormValue("attending"),
|
|
}
|
|
|
|
if err := data.UpdatePlayer(session, originalName, updated); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/setup", http.StatusSeeOther)
|
|
}
|