Update Filters, Limit, Search
This commit is contained in:
@@ -20,7 +20,11 @@ func NewCollectionHandler() *CollectionHandler {
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetAll(c *fiber.Ctx) error {
|
||||
collections, err := h.Repo.FindAll()
|
||||
limit := c.QueryInt("limit", 10) // default 10
|
||||
offset := c.QueryInt("offset", 0) // default 0
|
||||
search := c.Query("search", "")
|
||||
|
||||
collections, err := h.Repo.FindAll(limit, offset, search)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch collections"})
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ func NewColourHandler() *ColourHandler {
|
||||
}
|
||||
|
||||
func (h *ColourHandler) GetAll(c *fiber.Ctx) error {
|
||||
colours, err := h.Repo.FindAll()
|
||||
limit := c.QueryInt("limit", 10) // default 10
|
||||
offset := c.QueryInt("offset", 0) // default 0
|
||||
search := c.Query("search", "")
|
||||
|
||||
colours, err := h.Repo.FindAll(limit, offset, search)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch colours"})
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ func NewCategoryHandler() *CategoryHandler {
|
||||
}
|
||||
|
||||
func (h *CategoryHandler) GetAll(c *fiber.Ctx) error {
|
||||
categories, err := h.Repo.FindAll()
|
||||
limit := c.QueryInt("limit", 10) // default 10
|
||||
offset := c.QueryInt("offset", 0) // default 0
|
||||
search := c.Query("search", "")
|
||||
|
||||
categories, err := h.Repo.FindAll(limit, offset, search)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch categories"})
|
||||
}
|
||||
|
||||
@@ -21,7 +21,15 @@ func NewProductHandler() *ProductHandler {
|
||||
}
|
||||
|
||||
func (h *ProductHandler) GetAll(c *fiber.Ctx) error {
|
||||
products, err := h.Repo.FindAll()
|
||||
limit := c.QueryInt("limit", 10) // default 10
|
||||
offset := c.QueryInt("offset", 0) // default 0
|
||||
search := c.Query("search", "")
|
||||
categoryID := c.QueryInt("category_id", 0)
|
||||
collectionID := c.QueryInt("collection_id", 0)
|
||||
colourID := c.QueryInt("colour_id", 0)
|
||||
sizeID := c.QueryInt("size_id", 0)
|
||||
|
||||
products, err := h.Repo.FindAll(limit, offset, search, uint(categoryID), uint(collectionID), uint(colourID), uint(sizeID))
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch products"})
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ func NewSizeHandler() *SizeHandler {
|
||||
}
|
||||
|
||||
func (h *SizeHandler) GetAll(c *fiber.Ctx) error {
|
||||
sizes, err := h.Repo.FindAll()
|
||||
limit := c.QueryInt("limit", 10) // default 10
|
||||
offset := c.QueryInt("offset", 0) // default 0
|
||||
search := c.Query("search", "")
|
||||
|
||||
sizes, err := h.Repo.FindAll(limit, offset, search)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch sizes"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user