mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Merge branch 'dev/teguh' into 'development'
feat[BE]: add get all nonstock by supplier id on nonstock get all See merge request mbugroup/lti-api!125
This commit is contained in:
@@ -23,10 +23,12 @@ func NewNonstockController(nonstockService service.NonstockService) *NonstockCon
|
||||
}
|
||||
|
||||
func (u *NonstockController) 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", ""),
|
||||
SupplierID: uint(c.QueryInt("supplier_id", 0)),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
|
||||
@@ -58,15 +58,15 @@ func (s nonstockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
|
||||
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.SupplierID > 0 {
|
||||
db = db.Joins("INNER JOIN nonstock_suppliers ON nonstock_suppliers.nonstock_id = nonstocks.id").
|
||||
Where("nonstock_suppliers.supplier_id = ?", params.SupplierID).
|
||||
Distinct()
|
||||
}
|
||||
|
||||
db = s.withRelations(db)
|
||||
|
||||
if params.Search != "" {
|
||||
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ 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"`
|
||||
SupplierID *uint `query:"supplier_id" validate:"omitempty,gt=0"`
|
||||
SupplierID uint `query:"supplier_id" validate:"omitempty,gt=0"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user