From b73f13ee7688aacff9608b47c87787fd00b55d8c Mon Sep 17 00:00:00 2001 From: giovanni Date: Mon, 23 Feb 2026 11:46:31 +0700 Subject: [PATCH] add query param filter has laying --- .../locations/controllers/location.controller.go | 9 +++++---- .../master/locations/services/location.service.go | 11 +++++++++++ .../locations/validations/location.validation.go | 9 +++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/internal/modules/master/locations/controllers/location.controller.go b/internal/modules/master/locations/controllers/location.controller.go index f360a9c9..7a3bb5ff 100644 --- a/internal/modules/master/locations/controllers/location.controller.go +++ b/internal/modules/master/locations/controllers/location.controller.go @@ -24,10 +24,11 @@ func NewLocationController(locationService service.LocationService) *LocationCon func (u *LocationController) GetAll(c *fiber.Ctx) error { query := &validation.Query{ - Page: c.QueryInt("page", 1), - Limit: c.QueryInt("limit", 10), - Search: c.Query("search", ""), - AreaId: c.QueryInt("area_id", 0), + Page: c.QueryInt("page", 1), + Limit: c.QueryInt("limit", 10), + Search: c.Query("search", ""), + AreaId: c.QueryInt("area_id", 0), + HasLaying: c.QueryBool("has_laying", false), } if query.Page < 1 || query.Limit < 1 { diff --git a/internal/modules/master/locations/services/location.service.go b/internal/modules/master/locations/services/location.service.go index 03f6cf45..8aa01dbf 100644 --- a/internal/modules/master/locations/services/location.service.go +++ b/internal/modules/master/locations/services/location.service.go @@ -60,6 +60,17 @@ func (s locationService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit if params.AreaId != 0 { 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") }) diff --git a/internal/modules/master/locations/validations/location.validation.go b/internal/modules/master/locations/validations/location.validation.go index a2ac6175..fbdc1572 100644 --- a/internal/modules/master/locations/validations/location.validation.go +++ b/internal/modules/master/locations/validations/location.validation.go @@ -13,8 +13,9 @@ type Update struct { } type Query struct { - Page int `query:"page" validate:"omitempty,number,min=1"` - Limit int `query:"limit" validate:"omitempty,number,min=1,max=500"` - Search string `query:"search" validate:"omitempty,max=50"` - AreaId int `query:"area_id" validate:"omitempty,number,gt=0"` + Page int `query:"page" validate:"omitempty,number,min=1"` + Limit int `query:"limit" validate:"omitempty,number,min=1,max=500"` + Search string `query:"search" validate:"omitempty,max=50"` + AreaId int `query:"area_id" validate:"omitempty,number,gt=0"` + HasLaying bool `query:"has_laying"` }