Update Filters, Limit, Search

This commit is contained in:
2025-06-27 14:30:55 +07:00
parent 9b1f58d783
commit a9c8e6c1a6
10 changed files with 105 additions and 16 deletions
@@ -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"})
}
+5 -1
View File
@@ -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"})
}
+9 -1
View File
@@ -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"})
}
+5 -1
View File
@@ -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"})
}