mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +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 {
|
||||
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 != "" {
|
||||
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user