Use real event data on vote page
This commit is contained in:
parent
e964123131
commit
f9b1ddeb5f
@ -134,7 +134,7 @@ func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetEventQuery struct {
|
type GetEventQuery struct {
|
||||||
AlphaID, AdminCode string
|
AlphaID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetEventResult struct {
|
type GetEventResult struct {
|
||||||
@ -174,6 +174,7 @@ func (s *Store) GetEvent(ctx context.Context, query GetEventQuery) (GetEventResu
|
|||||||
return GetEventResult{}, err
|
return GetEventResult{}, err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
|
// TODO return a constant or a specific error type for Not Found
|
||||||
return GetEventResult{}, errors.New("not found")
|
return GetEventResult{}, errors.New("not found")
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -122,15 +122,23 @@ func voteForm(disabled bool, st voteState) hm.Term {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) handleVote(w http.ResponseWriter, r *http.Request) {
|
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{
|
state := voteState{
|
||||||
name: "Suzie Q",
|
earliestDate: event.EarliestDate,
|
||||||
earliestDate: time.Date(2006, time.May, 3, 0, 0, 0, 0, time.UTC),
|
latestDate: event.LatestDate,
|
||||||
latestDate: time.Date(2006, time.May, 8, 0, 0, 0, 0, time.UTC),
|
|
||||||
}
|
}
|
||||||
body := hm.Terms{
|
body := hm.Terms{
|
||||||
e.H2()(hm.Text("Billy's birthday party")),
|
e.H2()(hm.Text(event.Name)),
|
||||||
e.P()(hm.Text("At Billy's house. Bring presents. Eat cake.")),
|
e.P()(hm.Text(event.Description)),
|
||||||
voteForm(false, state),
|
voteForm(false, state),
|
||||||
}
|
}
|
||||||
_ = h.writePage(w, body)
|
_ = h.writePage(w, body)
|
||||||
@ -212,6 +220,10 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) {
|
|||||||
adminQuery.Add(keyAdminCode, event.AdminCode)
|
adminQuery.Add(keyAdminCode, event.AdminCode)
|
||||||
adminURL := h.baseURL + pathAdmin + "?" + adminQuery.Encode()
|
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"
|
const dateDisplayFmt = "Monday, January 2, 2006"
|
||||||
|
|
||||||
body := hm.Terms{
|
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)),
|
e.A(a.Href(adminURL))(hm.Text(adminURL)),
|
||||||
hm.Text("."),
|
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")),
|
e.H3()(hm.Text("Name")),
|
||||||
hm.Text(eventName),
|
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) {
|
func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
|
// TODO authenticate with admin code
|
||||||
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
|
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
|
||||||
AlphaID: query.Get(keyEventID),
|
AlphaID: query.Get(keyEventID),
|
||||||
AdminCode: query.Get(keyAdminCode),
|
|
||||||
})
|
})
|
||||||
|
// TODO return 404 if event not found
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(w, err)
|
fmt.Fprint(w, err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user