|
| 1 | +package routes |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/gofiber/fiber/v2" |
| 5 | + |
| 6 | + "example.choreo.dev/internal/controllers" |
| 7 | + "example.choreo.dev/internal/utils" |
| 8 | +) |
| 9 | + |
| 10 | +func registerCategoryRoutes(router fiber.Router) { |
| 11 | + r := router.Group("/category") |
| 12 | + r.Post("/", CreateCategory) |
| 13 | + r.Get("/", ListCategories) |
| 14 | +} |
| 15 | + |
| 16 | +// CreateCategory |
| 17 | +// @Summary Add pet to the store |
| 18 | +// @Accept json |
| 19 | +// @Produce json |
| 20 | +// @Param request body controllers.AddCategoryRequest true "pet details" |
| 21 | +// @Router /api/v1/category [post] |
| 22 | +// @Failure 409 {object} any |
| 23 | +// @Success 200 {object} controllers.AddCategoryResponse "ok" |
| 24 | +func CreateCategory(c *fiber.Ctx) error { |
| 25 | + ctx := utils.GetRequestContext(c) |
| 26 | + var req controllers.AddCategoryRequest |
| 27 | + |
| 28 | + if err := c.BodyParser(&req); err != nil { |
| 29 | + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ |
| 30 | + "status": "error", |
| 31 | + "details": "failed to parse payload", |
| 32 | + }) |
| 33 | + } |
| 34 | + |
| 35 | + res, err := categoryController.AddCategory(ctx, req) |
| 36 | + if err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + return c.Status(fiber.StatusOK).JSON(res) |
| 40 | +} |
| 41 | + |
| 42 | +// ListCategories |
| 43 | +// @Summary List available categories |
| 44 | +// @Produce json |
| 45 | +// @Router /api/v1/category [get] |
| 46 | +// @Success 200 {object} controllers.ListCategoriesResponse "ok" |
| 47 | +func ListCategories(c *fiber.Ctx) error { |
| 48 | + ctx := utils.GetRequestContext(c) |
| 49 | + |
| 50 | + res, err := categoryController.ListCategories(ctx) |
| 51 | + if err != nil { |
| 52 | + return err |
| 53 | + } |
| 54 | + return c.Status(fiber.StatusOK).JSON(res) |
| 55 | +} |
0 commit comments