package group import ( "errors" "html/template" "net/http" "git.cliffbreak.de/haveachin/scoreboard/data" "git.cliffbreak.de/haveachin/scoreboard/features" "git.cliffbreak.de/haveachin/scoreboard/features/weberror" "git.cliffbreak.de/haveachin/scoreboard/response" "git.cliffbreak.de/haveachin/scoreboard/service/filter" "git.cliffbreak.de/haveachin/scoreboard/service/id" "github.com/go-chi/chi" ) func queryOneHandler(s features.Service, t *template.Template) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { response.WebHandler(w, response.WebHandlerFunc(func() (response.Page, int) { if chi.URLParam(r, "id") == "" { return weberror.NewPage(*t, errors.New("No id in request"), http.StatusBadRequest), http.StatusBadRequest } id, err := id.ParseFromRequest(r) if err != nil { return weberror.NewPage(*t, err, http.StatusBadRequest), http.StatusBadRequest } var group data.Group if err := s.QueryOne(&group, &filter.Filter{"_id": *id}); err != nil { return weberror.NewPage(*t, err, http.StatusBadRequest), http.StatusBadRequest } var games []data.Game if err := s.Query(&games, &filter.Filter{}); err != nil { return weberror.NewPage(*t, err, http.StatusBadRequest), http.StatusBadRequest } return newDetailPage(*t, group, games), http.StatusOK })) }) } func queryHandler(s features.Service, t *template.Template) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { response.WebHandler(w, response.WebHandlerFunc(func() (response.Page, int) { var groups []data.Group if err := s.Query(&groups, &filter.Filter{}); err != nil { return weberror.NewPage(*t, err, http.StatusBadRequest), http.StatusBadRequest } return newMasterPage(*t, groups), http.StatusOK })) }) }