mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
feat: add more filters
This commit is contained in:
@@ -25,9 +25,10 @@ func NewProductStockController(productStockService service.ProductStockService)
|
||||
|
||||
func (u *ProductStockController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
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")
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ type Update struct {
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user