diff --git a/cmd/web/playershandler.go b/cmd/web/playershandler.go new file mode 100644 index 0000000..c12c023 --- /dev/null +++ b/cmd/web/playershandler.go @@ -0,0 +1,86 @@ +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) +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 01c2b1d..3cbc0a5 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -48,6 +48,18 @@ func routes(r *chi.Mux) { sendReminderHandler(w, r) }) + r.Post("/admin/players/add", func(w http.ResponseWriter, r *http.Request) { + addPlayerHandler(w, r) + }) + + r.Post("/admin/players/delete", func(w http.ResponseWriter, r *http.Request) { + deletePlayerHandler(w, r) + }) + + r.Post("/admin/players/edit", func(w http.ResponseWriter, r *http.Request) { + editPlayerHandler(w, r) + }) + r.Get("/sessioninfo", func(w http.ResponseWriter, r *http.Request) { session, dataErr := data.ReadSessionData() if dataErr != nil { diff --git a/cmd/web/templates/header_templ.go b/cmd/web/templates/header_templ.go index c72a9f5..d79d245 100644 --- a/cmd/web/templates/header_templ.go +++ b/cmd/web/templates/header_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,11 +29,11 @@ func Header() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Are We Playing?") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Are We Playing?") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/index_templ.go b/cmd/web/templates/index_templ.go index d226c36..584c4ea 100644 --- a/cmd/web/templates/index_templ.go +++ b/cmd/web/templates/index_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,7 +29,7 @@ func MainPage() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -37,11 +37,11 @@ func MainPage() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/login_templ.go b/cmd/web/templates/login_templ.go index becaca4..45a1485 100644 --- a/cmd/web/templates/login_templ.go +++ b/cmd/web/templates/login_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,7 +29,7 @@ func Login() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -37,11 +37,11 @@ func Login() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Please sign in

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

Please sign in

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/pagebody_templ.go b/cmd/web/templates/pagebody_templ.go index 1df621c..8aa7010 100644 --- a/cmd/web/templates/pagebody_templ.go +++ b/cmd/web/templates/pagebody_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -33,7 +33,7 @@ func PageBody(session data.Session) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Next Session: ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
Next Session: ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -46,45 +46,45 @@ func PageBody(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
AttendingPlayer
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, player := range session.Players { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
AttendingPlayer
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" hx-swap=\"innerHTML\" hx-target=\"#session-info\" hx-trigger=\"click\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if player.Attending == "yes" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else if player.Attending == "no" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -97,17 +97,17 @@ func PageBody(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if session.Status == "planned" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "
Status: ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -120,12 +120,12 @@ func PageBody(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else if session.Status == "canceled" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "
Status: ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -138,12 +138,12 @@ func PageBody(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
Status: ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -156,16 +156,16 @@ func PageBody(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/save_setup_templ.go b/cmd/web/templates/save_setup_templ.go index 27f84b3..4d4e34c 100644 --- a/cmd/web/templates/save_setup_templ.go +++ b/cmd/web/templates/save_setup_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,7 +29,7 @@ func SaveSetup(status string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -37,7 +37,7 @@ func SaveSetup(status string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -50,11 +50,11 @@ func SaveSetup(status string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/sendemail_templ.go b/cmd/web/templates/sendemail_templ.go index 2ed3e3f..c4d73c7 100644 --- a/cmd/web/templates/sendemail_templ.go +++ b/cmd/web/templates/sendemail_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,7 +29,7 @@ func SendEmail(status string, msg string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -37,7 +37,7 @@ func SendEmail(status string, msg string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -50,7 +50,7 @@ func SendEmail(status string, msg string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -63,11 +63,11 @@ func SendEmail(status string, msg string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/sendreminder_templ.go b/cmd/web/templates/sendreminder_templ.go index 8f5df17..843dfcb 100644 --- a/cmd/web/templates/sendreminder_templ.go +++ b/cmd/web/templates/sendreminder_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -29,7 +29,7 @@ func SendReminder(to string, subject string, text, msg string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -37,33 +37,33 @@ func SendReminder(to string, subject string, text, msg string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Send Reminder

Send Reminder

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if msg == "" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if msg != "" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -109,16 +109,16 @@ func SendReminder(to string, subject string, text, msg string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + return nil }) } diff --git a/cmd/web/templates/setup.templ b/cmd/web/templates/setup.templ index edc5dba..322bf15 100644 --- a/cmd/web/templates/setup.templ +++ b/cmd/web/templates/setup.templ @@ -63,11 +63,143 @@ templ Setup(session data.Session) { + +
+
+

Players

+ +
+
+
+
+ + + + + + + + + + + for _, p := range session.Players { + + + + + + + } + +
NameEmailGMActions
{ p.Name }{ p.Email } + if p.Gm { + GM + } + + +
+ + +
+
+
+
+ + + + + + + + + -} \ No newline at end of file +} diff --git a/cmd/web/templates/setup_templ.go b/cmd/web/templates/setup_templ.go index 06f4bd8..57a0ec3 100644 --- a/cmd/web/templates/setup_templ.go +++ b/cmd/web/templates/setup_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.778 +// templ: version: v0.3.1020 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -34,7 +34,7 @@ func Setup(session data.Session) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -42,24 +42,135 @@ func Setup(session data.Session) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Setup

Setup

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\">

Players

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - return templ_7745c5c3_Err + for _, p := range session.Players { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
NameEmailGMActions
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `cmd/web/templates/setup.templ`, Line: 89, Col: 44} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(p.Email) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `cmd/web/templates/setup.templ`, Line: 90, Col: 45} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if p.Gm { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "GM") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
Add Player
Edit Player
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil }) } diff --git a/go.mod b/go.mod index 1425bfd..f72be07 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,9 @@ module github.com/hculpan/areweplaying -go 1.23.0 - -toolchain go1.24.0 +go 1.25.0 require ( - github.com/a-h/templ v0.3.833 + github.com/a-h/templ v0.3.1020 github.com/go-chi/chi/v5 v5.2.1 ) diff --git a/go.sum b/go.sum index fae8600..8a46c46 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,15 @@ -github.com/a-h/templ v0.2.543 h1:8YyLvyUtf0/IE2nIwZ62Z/m2o2NqwhnMynzOL78Lzbk= -github.com/a-h/templ v0.2.543/go.mod h1:jP908DQCwI08IrnTalhzSEH9WJqG/Q94+EODQcJGFUA= -github.com/a-h/templ v0.3.833 h1:L/KOk/0VvVTBegtE0fp2RJQiBm7/52Zxv5fqlEHiQUU= -github.com/a-h/templ v0.3.833/go.mod h1:cAu4AiZhtJfBjMY0HASlyzvkrtjnHWPeEsyGK2YYmfk= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/a-h/templ v0.3.1020 h1:ypAT/L5ySWEnZ6Zft/5yfoWXYYkhFNvEFOeeqecg4tw= +github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/emersion/go-imap v1.2.1 h1:+s9ZjMEjOB8NzZMVTM3cCenz2JrQIGGo5j1df19WjTA= github.com/emersion/go-imap v1.2.1/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY= github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4= -github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ= github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 h1:oP4q0fw+fOSWn3DfFi4EXdT+B+gTtzx8GC9xsc26Znk= github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= -github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= -github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8= github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= @@ -27,16 +19,11 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= diff --git a/pkg/data/loaddata.go b/pkg/data/loaddata.go index 1297f2c..8846977 100644 --- a/pkg/data/loaddata.go +++ b/pkg/data/loaddata.go @@ -2,6 +2,7 @@ package data import ( "encoding/json" + "fmt" "os" ) @@ -33,3 +34,29 @@ func PersistSession(session Session) error { err = os.WriteFile("players.json", jsonData, 0644) return err } + +func AddPlayer(session Session, p Player) error { + session.Players = append(session.Players, p) + return PersistSession(session) +} + +func DeletePlayer(session Session, name string) error { + players := make([]Player, 0, len(session.Players)) + for _, p := range session.Players { + if p.Name != name { + players = append(players, p) + } + } + session.Players = players + return PersistSession(session) +} + +func UpdatePlayer(session Session, originalName string, updated Player) error { + for i, p := range session.Players { + if p.Name == originalName { + session.Players[i] = updated + return PersistSession(session) + } + } + return fmt.Errorf("player %q not found", originalName) +} diff --git a/pkg/email/fetch.go b/pkg/email/fetch.go index 961bf61..e6fe9f3 100644 --- a/pkg/email/fetch.go +++ b/pkg/email/fetch.go @@ -88,6 +88,7 @@ func fetchEmails(imapClient *client.Client) ([]Email, error) { email := NewEmail( []string{toAddress}, + []string{}, fromAddress, msg.Envelope.Subject, string(body),