mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 14:55:42 +00:00
feat(BE): add supplier_id filter to GetAll method and update validation for query parameters
This commit is contained in:
@@ -59,6 +59,14 @@ func (s nonstockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
|||||||
|
|
||||||
nonstocks, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
nonstocks, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||||
db = s.withRelations(db)
|
db = s.withRelations(db)
|
||||||
|
|
||||||
|
if params.SupplierID != nil {
|
||||||
|
supplierID := *params.SupplierID
|
||||||
|
db = db.Joins("JOIN nonstock_suppliers ON nonstock_suppliers.nonstock_id = nonstocks.id").
|
||||||
|
Where("nonstock_suppliers.supplier_id = ?", supplierID).
|
||||||
|
Group("nonstocks.id") // Prevent duplicates from join
|
||||||
|
}
|
||||||
|
|
||||||
if params.Search != "" {
|
if params.Search != "" {
|
||||||
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ type Update struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||||
Search string `query:"search" validate:"omitempty,max=50"`
|
Search string `query:"search" validate:"omitempty,max=50"`
|
||||||
|
SupplierID *uint `query:"supplier_id" validate:"omitempty,gt=0"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user