mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 14:55:42 +00:00
fix(be): update nonstock query to use SupplierID as a non-pointer type
This commit is contained in:
@@ -23,10 +23,12 @@ func NewNonstockController(nonstockService service.NonstockService) *NonstockCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *NonstockController) GetAll(c *fiber.Ctx) error {
|
func (u *NonstockController) GetAll(c *fiber.Ctx) error {
|
||||||
|
|
||||||
query := &validation.Query{
|
query := &validation.Query{
|
||||||
Page: c.QueryInt("page", 1),
|
Page: c.QueryInt("page", 1),
|
||||||
Limit: c.QueryInt("limit", 10),
|
Limit: c.QueryInt("limit", 10),
|
||||||
Search: c.Query("search", ""),
|
Search: c.Query("search", ""),
|
||||||
|
SupplierID: uint(c.QueryInt("supplier_id", 0)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
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
|
offset := (params.Page - 1) * params.Limit
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if params.SupplierID != nil {
|
if params.SupplierID > 0 {
|
||||||
supplierID := *params.SupplierID
|
db = db.Joins("INNER JOIN nonstock_suppliers ON nonstock_suppliers.nonstock_id = nonstocks.id").
|
||||||
db = db.Joins("JOIN nonstock_suppliers ON nonstock_suppliers.nonstock_id = nonstocks.id").
|
Where("nonstock_suppliers.supplier_id = ?", params.SupplierID).
|
||||||
Where("nonstock_suppliers.supplier_id = ?", supplierID).
|
Distinct()
|
||||||
Group("nonstocks.id") // Prevent duplicates from join
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db = s.withRelations(db)
|
||||||
|
|
||||||
if params.Search != "" {
|
if params.Search != "" {
|
||||||
return db.Where("name LIKE ?", "%"+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"`
|
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"`
|
SupplierID uint `query:"supplier_id" validate:"omitempty,gt=0"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user