add query param location id

This commit is contained in:
giovanni
2026-04-13 10:51:12 +07:00
parent 30a47ffc71
commit d1612e5c65
3 changed files with 14 additions and 0 deletions
@@ -32,6 +32,7 @@ func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
KandangId: uint(c.QueryInt("kandang_id", 0)),
Category: c.Query("category", ""),
AreaId: uint(c.QueryInt("area_id", 0)),
LocationId: uint(c.QueryInt("location_id", 0)),
SortBy: c.Query("sort_by", ""),
SortOrder: c.Query("sort_order", ""),
StepName: c.Query("step_name", ""),
@@ -19,6 +19,7 @@ type Query struct {
KandangId uint `query:"kandang_id" validate:"omitempty"`
Category string `query:"category" validate:"omitempty,oneof=Growing Laying"`
AreaId uint `query:"area_id" validate:"omitempty"`
LocationId uint `query:"location_id" validate:"omitempty,number,gt=0"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=created_at period"`
SortOrder string `query:"sort_order" validate:"omitempty,oneof=ASC DESC"`
StepName string `query:"step_name" validate:"omitempty,max=50"`
@@ -178,6 +178,10 @@ func (r *projectFlockKandangRepositoryImpl) GetAllWithFilters(ctx context.Contex
if query.AreaId > 0 {
q = q.Where("\"project_flocks\".\"area_id\" = ?", query.AreaId)
}
if query.LocationId > 0 {
q = q.Where("\"kandangs\".\"location_id\" = ?", query.LocationId)
}
}
if err := q.Model(&entity.ProjectFlockKandang{}).Count(&total).Error; err != nil {
@@ -276,6 +280,10 @@ func (r *projectFlockKandangRepositoryImpl) GetAllWithFiltersScoped(ctx context.
if query.AreaId > 0 {
q = q.Where("\"project_flocks\".\"area_id\" = ?", query.AreaId)
}
if query.LocationId > 0 {
q = q.Where("\"kandangs\".\"location_id\" = ?", query.LocationId)
}
}
if err := q.Model(&entity.ProjectFlockKandang{}).Count(&total).Error; err != nil {
@@ -362,6 +370,10 @@ func (r *projectFlockKandangRepositoryImpl) GetAllNameWithPeriodeScoped(ctx cont
if params.AreaId > 0 {
q = q.Where("\"project_flocks\".\"area_id\" = ?", params.AreaId)
}
if params.LocationId > 0 {
q = q.Where("\"kandangs\".\"location_id\" = ?", params.LocationId)
}
}
if err := q.Count(&total).Error; err != nil {