mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'feat/location' into 'development'
[FEAT][BE]: add query param filter has laying master data location See merge request mbugroup/lti-api!334
This commit is contained in:
@@ -24,10 +24,11 @@ func NewLocationController(locationService service.LocationService) *LocationCon
|
|||||||
|
|
||||||
func (u *LocationController) GetAll(c *fiber.Ctx) error {
|
func (u *LocationController) 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", ""),
|
||||||
AreaId: c.QueryInt("area_id", 0),
|
AreaId: c.QueryInt("area_id", 0),
|
||||||
|
HasLaying: c.QueryBool("has_laying", false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
if query.Page < 1 || query.Limit < 1 {
|
||||||
|
|||||||
@@ -60,6 +60,17 @@ func (s locationService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
|||||||
if params.AreaId != 0 {
|
if params.AreaId != 0 {
|
||||||
db = db.Where("area_id = ?", params.AreaId)
|
db = db.Where("area_id = ?", params.AreaId)
|
||||||
}
|
}
|
||||||
|
if params.HasLaying {
|
||||||
|
db = db.Where(`
|
||||||
|
EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM project_flocks pf
|
||||||
|
WHERE pf.location_id = locations.id
|
||||||
|
AND pf.category = ?
|
||||||
|
AND pf.deleted_at IS NULL
|
||||||
|
)
|
||||||
|
`, utils.ProjectFlockCategoryLaying)
|
||||||
|
}
|
||||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ 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=500"`
|
Limit int `query:"limit" validate:"omitempty,number,min=1,max=500"`
|
||||||
Search string `query:"search" validate:"omitempty,max=50"`
|
Search string `query:"search" validate:"omitempty,max=50"`
|
||||||
AreaId int `query:"area_id" validate:"omitempty,number,gt=0"`
|
AreaId int `query:"area_id" validate:"omitempty,number,gt=0"`
|
||||||
|
HasLaying bool `query:"has_laying"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user