mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
fix(BE-273): add object nonstock and supplier in response get one and fix name base to relation in dto
This commit is contained in:
@@ -39,7 +39,12 @@ func NewSupplierService(repo repository.SupplierRepository, validate *validator.
|
||||
}
|
||||
|
||||
func (s supplierService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("CreatedUser")
|
||||
return db.
|
||||
Preload("CreatedUser").
|
||||
Preload("ProductSuppliers.Product.Uom").
|
||||
Preload("ProductSuppliers.Product.Flags").
|
||||
Preload("NonstockSuppliers.Nonstock.Uom").
|
||||
Preload("NonstockSuppliers.Nonstock.Flags")
|
||||
}
|
||||
|
||||
func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Supplier, int64, error) {
|
||||
@@ -47,6 +52,14 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if params.Category != "" {
|
||||
category := strings.ToUpper(params.Category)
|
||||
if category != "BOP" && category != "SAPRONAK" {
|
||||
return nil, 0, fiber.NewError(fiber.StatusBadRequest, "Invalid supplier category")
|
||||
}
|
||||
params.Category = category
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
|
||||
suppliers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
@@ -54,6 +67,11 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
if params.Search != "" {
|
||||
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
|
||||
if params.Category != "" {
|
||||
db = db.Where("category LIKE ?", "%"+params.Category+"%")
|
||||
}
|
||||
|
||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user