Use real event data on vote page

This commit is contained in:
2020-04-13 23:29:40 -06:00
parent e964123131
commit f9b1ddeb5f
2 changed files with 28 additions and 9 deletions

View File

@ -122,15 +122,23 @@ func voteForm(disabled bool, st voteState) hm.Term {
}
func (h *handler) handleVote(w http.ResponseWriter, r *http.Request) {
// TODO use actual data
query := r.URL.Query()
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
AlphaID: query.Get(keyEventID),
})
// TODO return 404 if event not found
if err != nil {
fmt.Fprint(w, err)
return
}
state := voteState{
name: "Suzie Q",
earliestDate: time.Date(2006, time.May, 3, 0, 0, 0, 0, time.UTC),
latestDate: time.Date(2006, time.May, 8, 0, 0, 0, 0, time.UTC),
earliestDate: event.EarliestDate,
latestDate: event.LatestDate,
}
body := hm.Terms{
e.H2()(hm.Text("Billy's birthday party")),
e.P()(hm.Text("At Billy's house. Bring presents. Eat cake.")),
e.H2()(hm.Text(event.Name)),
e.P()(hm.Text(event.Description)),
voteForm(false, state),
}
_ = h.writePage(w, body)
@ -212,6 +220,10 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) {
adminQuery.Add(keyAdminCode, event.AdminCode)
adminURL := h.baseURL + pathAdmin + "?" + adminQuery.Encode()
var voteQuery = make(url.Values)
voteQuery.Add(keyEventID, event.AlphaID)
voteURL := h.baseURL + pathVote + "?" + voteQuery.Encode()
const dateDisplayFmt = "Monday, January 2, 2006"
body := hm.Terms{
@ -221,6 +233,11 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) {
e.A(a.Href(adminURL))(hm.Text(adminURL)),
hm.Text("."),
),
e.P()(
hm.Text("Your guests can vote on times at "),
e.A(a.Href(voteURL))(hm.Text(voteURL)),
hm.Text("."),
),
e.H3()(hm.Text("Name")),
hm.Text(eventName),
@ -239,10 +256,11 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) {
func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
// TODO authenticate with admin code
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
AlphaID: query.Get(keyEventID),
AdminCode: query.Get(keyAdminCode),
AlphaID: query.Get(keyEventID),
})
// TODO return 404 if event not found
if err != nil {
fmt.Fprint(w, err)
return