diff --git a/back/store.go b/back/store.go index ca9b750..9b53c25 100644 --- a/back/store.go +++ b/back/store.go @@ -134,7 +134,7 @@ func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result } type GetEventQuery struct { - AlphaID, AdminCode string + AlphaID string } type GetEventResult struct { @@ -174,6 +174,7 @@ func (s *Store) GetEvent(ctx context.Context, query GetEventQuery) (GetEventResu return GetEventResult{}, err } if !found { + // TODO return a constant or a specific error type for Not Found return GetEventResult{}, errors.New("not found") } return result, nil diff --git a/front/server.go b/front/server.go index e88e1c3..678467d 100644 --- a/front/server.go +++ b/front/server.go @@ -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