Update Filters, Limit, Search, Page

This commit is contained in:
2025-06-27 15:29:08 +07:00
parent a9c8e6c1a6
commit 8873095102
18 changed files with 202 additions and 38 deletions
@@ -20,11 +20,12 @@ func NewCollectionHandler() *CollectionHandler {
}
func (h *CollectionHandler) GetAll(c *fiber.Ctx) error {
limit := c.QueryInt("limit", 10) // default 10
offset := c.QueryInt("offset", 0) // default 0
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
collections, err := h.Repo.FindAll(limit, offset, search)
collections, err := h.Repo.FindAll(page, limit, offset, search)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch collections"})
}
+4 -3
View File
@@ -20,11 +20,12 @@ func NewColourHandler() *ColourHandler {
}
func (h *ColourHandler) GetAll(c *fiber.Ctx) error {
limit := c.QueryInt("limit", 10) // default 10
offset := c.QueryInt("offset", 0) // default 0
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
colours, err := h.Repo.FindAll(limit, offset, search)
colours, err := h.Repo.FindAll(page, limit, offset, search)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch colours"})
}
@@ -20,11 +20,12 @@ func NewCategoryHandler() *CategoryHandler {
}
func (h *CategoryHandler) GetAll(c *fiber.Ctx) error {
limit := c.QueryInt("limit", 10) // default 10
offset := c.QueryInt("offset", 0) // default 0
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
categories, err := h.Repo.FindAll(limit, offset, search)
categories, err := h.Repo.FindAll(page, limit, offset, search)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch categories"})
}
@@ -20,11 +20,18 @@ func NewProductComponentHandler() *ProductComponentHandler {
}
func (h *ProductComponentHandler) GetAll(c *fiber.Ctx) error {
result, err := h.Repo.FindAll()
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
productID := c.QueryInt("product_id", 0)
componenID := c.QueryInt("componen_id", 0)
components, err := h.Repo.FindAll(page, limit, offset, search, uint(productID), uint(componenID))
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch components"})
}
return c.JSON(result)
return c.JSON(components)
}
func (h *ProductComponentHandler) Create(c *fiber.Ctx) error {
+4 -3
View File
@@ -21,15 +21,16 @@ func NewProductHandler() *ProductHandler {
}
func (h *ProductHandler) GetAll(c *fiber.Ctx) error {
limit := c.QueryInt("limit", 10) // default 10
offset := c.QueryInt("offset", 0) // default 0
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
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))
products, err := h.Repo.FindAll(page, 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,6 +5,7 @@ import (
"BE-MiniERP/modules/inventory/models"
"BE-MiniERP/modules/inventory/repository"
"strconv"
"time"
"github.com/gofiber/fiber/v2"
)
@@ -20,7 +21,39 @@ func NewProductionOrderHandler() *ProductionOrderHandler {
}
func (h *ProductionOrderHandler) GetAll(c *fiber.Ctx) error {
data, err := h.Repo.FindAll()
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
productID := c.QueryInt("product_id", 0)
startDateStr := c.Query("start_date", "")
endDateStr := c.Query("end_date", "")
warehouseID := c.QueryInt("origin_id", 0)
var startDate, endDate time.Time
var err error
// Parse start_date
if startDateStr != "" {
startDate, err = time.Parse("2006-01-02", startDateStr)
if err != nil {
return c.Status(400).JSON(fiber.Map{
"error": "Invalid start_date format. Use YYYY-MM-DD",
})
}
}
// Parse end_date
if endDateStr != "" {
endDate, err = time.Parse("2006-01-02", endDateStr)
if err != nil {
return c.Status(400).JSON(fiber.Map{
"error": "Invalid end_date format. Use YYYY-MM-DD",
})
}
}
data, err := h.Repo.FindAll(page, limit, offset, search, uint(productID), uint(warehouseID), startDate, endDate)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch production orders"})
}
+4 -3
View File
@@ -20,11 +20,12 @@ func NewSizeHandler() *SizeHandler {
}
func (h *SizeHandler) GetAll(c *fiber.Ctx) error {
limit := c.QueryInt("limit", 10) // default 10
offset := c.QueryInt("offset", 0) // default 0
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
sizes, err := h.Repo.FindAll(limit, offset, search)
sizes, err := h.Repo.FindAll(page, limit, offset, search)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch sizes"})
}
@@ -4,6 +4,7 @@ import (
"BE-MiniERP/database"
"BE-MiniERP/modules/inventory/models"
"BE-MiniERP/modules/inventory/repository"
"time"
"github.com/gofiber/fiber/v2"
)
@@ -19,7 +20,34 @@ func NewStockMovementHandler() *StockMovementHandler {
}
func (h *StockMovementHandler) GetAll(c *fiber.Ctx) error {
data, err := h.Repo.FindAll()
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
productID := c.QueryInt("product_id", 0)
dateStr := c.Query("date", "")
originID := c.QueryInt("origin_id", 0)
destinationID := c.QueryInt("destination_id", 0)
var selectedDate time.Time
var err error
if dateStr != "" {
selectedDate, err = time.Parse("2006-01-02", dateStr)
if err != nil {
return c.Status(400).JSON(fiber.Map{
"error": "Invalid date format. Use YYYY-MM-DD",
})
}
}
data, err := h.Repo.FindAll(
page, limit, offset,
search,
uint(productID), uint(originID), uint(destinationID),
selectedDate,
)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch stock movements"})
}
@@ -20,7 +20,12 @@ func NewWarehouseHandler() *WarehouseHandler {
}
func (h *WarehouseHandler) GetAll(c *fiber.Ctx) error {
warehouses, err := h.Repo.FindAll()
page := c.QueryInt("page", 1)
limit := c.QueryInt("limit", 10) // default 10
offset := (page - 1) * limit
search := c.Query("search", "")
warehouses, err := h.Repo.FindAll(page, limit, offset, search)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": "Failed to fetch warehouses"})
}