Merge branch 'codex/filter-improvement' into 'development'

feat: add more filters

See merge request mbugroup/lti-api!474
This commit is contained in:
Adnan Zahir
2026-04-25 12:27:46 +07:00
6 changed files with 27 additions and 12 deletions
@@ -28,6 +28,7 @@ func (u *ProductStockController) GetAll(c *fiber.Ctx) error {
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
ProductCategoryID: uint(c.QueryInt("product_category_id", 0)),
}
if query.Page < 1 || query.Limit < 1 {
@@ -129,6 +129,9 @@ func (s productStockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e
if params.Search != "" {
db = db.Where("products.name ILIKE ?", "%"+params.Search+"%")
}
if params.ProductCategoryID > 0 {
db = db.Where("products.product_category_id = ?", params.ProductCategoryID)
}
return db.Order("products.created_at DESC").Order("products.updated_at DESC")
})
@@ -12,4 +12,5 @@ type Query struct {
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
Search string `query:"search" validate:"omitempty,max=50"`
ProductCategoryID uint `query:"product_category_id" validate:"omitempty"`
}
@@ -28,6 +28,8 @@ func (u *TransferController) GetAll(c *fiber.Ctx) error {
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
ProductID: uint(c.QueryInt("product_id", 0)),
WarehouseID: uint(c.QueryInt("warehouse_id", 0)),
}
result, totalResults, err := u.TransferService.GetAll(c, query)
@@ -157,6 +157,12 @@ func (s transferService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
Where("movement_number ILIKE ? OR from_warehouses.name ILIKE ? OR to_warehouses.name ILIKE ?",
searchTerm, searchTerm, searchTerm)
}
if params.ProductID > 0 {
db = db.Joins("JOIN stock_transfer_details AS filter_std ON filter_std.stock_transfer_id = stock_transfers.id AND filter_std.deleted_at IS NULL AND filter_std.product_id = ?", params.ProductID)
}
if params.WarehouseID > 0 {
db = db.Where("stock_transfers.from_warehouse_id = ? OR stock_transfers.to_warehouse_id = ?", params.WarehouseID, params.WarehouseID)
}
return db.Order("created_at DESC").Order("updated_at DESC")
})
@@ -8,6 +8,8 @@ type Query struct {
Page int `query:"page" validate:"omitempty,number,min=1"`
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
Search string `query:"search" validate:"omitempty,max=50"`
ProductID uint `query:"product_id" validate:"omitempty"`
WarehouseID uint `query:"warehouse_id" validate:"omitempty"`
}
type TransferProduct struct {