package routes import ( "net/http" "git.red-panda.pet/pandaware/house/backend/db" "git.red-panda.pet/pandaware/house/backend/middleware" "git.red-panda.pet/pandaware/house/backend/router" ) func init() { routes["GET"]["/category"] = new(CategoriesGET) } type categoriesResponse struct { Categories []db.Category `json:"categories"` } type CategoriesGET struct{} // Authorize implements router.AuthorizedRoute. func (c *CategoriesGET) Authorize(ctx *router.Context) error { return middleware.Authenticated(ctx) } // Handle implements router.Route. func (c *CategoriesGET) Handle(ctx *router.Context) error { categories, err := ctx.Query.ListCategories(ctx) if err != nil { return ctx.GenericError(err, http.StatusInternalServerError) } return ctx.JSON(200, categoriesResponse{ Categories: categories, }) } var _ router.AuthorizedRoute = new(CategoriesGET)