initial commit
This commit is contained in:
commit
d40b69f1f9
58 changed files with 7919 additions and 0 deletions
37
backend/routes/categories.go
Normal file
37
backend/routes/categories.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue