Refactored ticket code into kiosk code.

This commit is contained in:
Pen Anderson 2026-03-05 16:31:08 -06:00
parent 72b245d6d6
commit 3eec81af7f
5 changed files with 110 additions and 190 deletions

View file

@ -6,26 +6,21 @@ import (
"strconv"
)
func (app *App) volunteerFromKioskToken(token string) (*Volunteer, error) {
return app.getVolunteerByKioskCode(token)
}
// handleKioskGet returns the volunteer's profile, current shift assignments, and
// available open shifts in their department. Authenticated by ticket code only —
// available open shifts in their department. Authenticated by kiosk code only —
// no JWT required.
func (app *App) handleKioskGet(w http.ResponseWriter, r *http.Request) {
token := r.PathValue("token")
t, err := app.getTicketByCode(token)
if err != nil || t == nil {
v, err := app.volunteerFromKioskToken(token)
if err != nil || v == nil {
writeError(w, "not found", http.StatusNotFound)
return
}
var v *Volunteer
if t.ParticipantID != nil {
v, _ = app.getVolunteerByParticipantID(*t.ParticipantID)
}
if v == nil {
writeError(w, "no volunteer record linked to this token", http.StatusNotFound)
return
}
assigned, _ := app.listShiftsForVolunteer(v.ID)
if assigned == nil {
assigned = []Shift{}
@ -56,19 +51,11 @@ func (app *App) handleKioskClaim(w http.ResponseWriter, r *http.Request) {
return
}
t, err := app.getTicketByCode(token)
if err != nil || t == nil {
v, err := app.volunteerFromKioskToken(token)
if err != nil || v == nil {
writeError(w, "not found", http.StatusNotFound)
return
}
var v *Volunteer
if t.ParticipantID != nil {
v, _ = app.getVolunteerByParticipantID(*t.ParticipantID)
}
if v == nil {
writeError(w, "no volunteer linked to this token", http.StatusNotFound)
return
}
force := r.URL.Query().Get("force") == "true"
@ -116,19 +103,11 @@ func (app *App) handleKioskUnclaim(w http.ResponseWriter, r *http.Request) {
return
}
t, err := app.getTicketByCode(token)
if err != nil || t == nil {
v, err := app.volunteerFromKioskToken(token)
if err != nil || v == nil {
writeError(w, "not found", http.StatusNotFound)
return
}
var v *Volunteer
if t.ParticipantID != nil {
v, _ = app.getVolunteerByParticipantID(*t.ParticipantID)
}
if v == nil {
writeError(w, "no volunteer linked to this token", http.StatusNotFound)
return
}
if err := app.unassignShift(v.ID, shiftID); err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)