From 28c6aaefac7ff4f8f9119be19b5c977092348e32 Mon Sep 17 00:00:00 2001 From: aguhh18 Date: Sun, 11 Jan 2026 21:09:15 +0700 Subject: [PATCH] feat(BE): refactor search queries to be case insensitive across all modules --- internal/modules/closings/services/closing.service.go | 2 +- .../expenses/repositories/expense_realization.repository.go | 2 +- internal/modules/expenses/services/expense.service.go | 2 +- .../repositories/product_warehouse.repository.go | 4 ++-- .../modules/inventory/transfers/services/transfer.service.go | 2 +- internal/modules/master/areas/services/area.service.go | 2 +- internal/modules/master/banks/services/bank.service.go | 2 +- .../modules/master/customers/services/customer.service.go | 5 +++-- .../modules/master/employees/services/employees.service.go | 2 +- internal/modules/master/fcrs/services/fcr.service.go | 2 +- internal/modules/master/flocks/services/flock.service.go | 2 +- internal/modules/master/kandangs/services/kandang.service.go | 5 +++-- .../modules/master/locations/services/location.service.go | 2 +- .../modules/master/nonstocks/services/nonstock.service.go | 2 +- .../phase-activities/services/phase-activity.service.go | 2 +- internal/modules/master/phasess/services/phases.service.go | 2 +- .../product-categories/services/product-category.service.go | 2 +- .../services/production-standard.service.go | 2 +- internal/modules/master/products/services/product.service.go | 2 +- .../modules/master/suppliers/services/supplier.service.go | 4 ++-- internal/modules/master/uoms/services/uom.service.go | 2 +- .../modules/master/warehouses/services/warehouse.service.go | 5 +++-- internal/modules/users/services/user.service.go | 2 +- 23 files changed, 31 insertions(+), 28 deletions(-) diff --git a/internal/modules/closings/services/closing.service.go b/internal/modules/closings/services/closing.service.go index a76085c4..a6fa9ae1 100644 --- a/internal/modules/closings/services/closing.service.go +++ b/internal/modules/closings/services/closing.service.go @@ -94,7 +94,7 @@ func (s closingService) GetAll(c *fiber.Ctx, params *validation.Query) ([]dto.Cl closings, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withClosingRelations(db) if params.Search != "" { - return db.Where("flock_name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(flock_name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/expenses/repositories/expense_realization.repository.go b/internal/modules/expenses/repositories/expense_realization.repository.go index 474b2962..235ef2e4 100644 --- a/internal/modules/expenses/repositories/expense_realization.repository.go +++ b/internal/modules/expenses/repositories/expense_realization.repository.go @@ -75,7 +75,7 @@ func (r *ExpenseRealizationRepositoryImpl) GetAllWithFilters(ctx context.Context Joins("LEFT JOIN suppliers ON suppliers.id = expenses.supplier_id") if filters.Search != "" { - db = db.Where("expenses.category LIKE ? OR expenses.reference_number LIKE ? OR expenses.po_number LIKE ? OR expenses.notes LIKE ? OR suppliers.name LIKE ?", + db = db.Where("LOWER(expenses.category) LIKE LOWER(?) OR LOWER(expenses.reference_number) LIKE LOWER(?) OR LOWER(expenses.po_number) LIKE LOWER(?) OR LOWER(expenses.notes) LIKE LOWER(?) OR LOWER(suppliers.name) LIKE LOWER(?)", "%"+filters.Search+"%", "%"+filters.Search+"%", "%"+filters.Search+"%", "%"+filters.Search+"%", "%"+filters.Search+"%") } diff --git a/internal/modules/expenses/services/expense.service.go b/internal/modules/expenses/services/expense.service.go index 3e50da26..d4b90065 100644 --- a/internal/modules/expenses/services/expense.service.go +++ b/internal/modules/expenses/services/expense.service.go @@ -92,7 +92,7 @@ func (s expenseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]expens expenses, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("category LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(category) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/inventory/product-warehouses/repositories/product_warehouse.repository.go b/internal/modules/inventory/product-warehouses/repositories/product_warehouse.repository.go index 6acb4f69..a4545636 100644 --- a/internal/modules/inventory/product-warehouses/repositories/product_warehouse.repository.go +++ b/internal/modules/inventory/product-warehouses/repositories/product_warehouse.repository.go @@ -399,11 +399,11 @@ func (r *ProductWarehouseRepositoryImpl) ListProductIDsByFlagPrefixes(ctx contex } like := prefix + "%" if !applied { - db = db.Where("flags.name LIKE ?", like) + db = db.Where("LOWER(flags.name) LIKE LOWER(?)", like) applied = true continue } - db = db.Or("flags.name LIKE ?", like) + db = db.Or("LOWER(flags.name) LIKE LOWER(?)", like) } if visibleStatus != nil { diff --git a/internal/modules/inventory/transfers/services/transfer.service.go b/internal/modules/inventory/transfers/services/transfer.service.go index dc6399d5..051b9ac5 100644 --- a/internal/modules/inventory/transfers/services/transfer.service.go +++ b/internal/modules/inventory/transfers/services/transfer.service.go @@ -99,7 +99,7 @@ func (s transferService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit transfers, total, err := s.StockTransferRepo.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - db = db.Where("movement_number LIKE ?", "%"+strings.TrimSpace(params.Search)+"%") + db = db.Where("LOWER(movement_number) LIKE LOWER(?)", "%"+strings.TrimSpace(params.Search)+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/areas/services/area.service.go b/internal/modules/master/areas/services/area.service.go index 0a976567..722f643f 100644 --- a/internal/modules/master/areas/services/area.service.go +++ b/internal/modules/master/areas/services/area.service.go @@ -52,7 +52,7 @@ func (s areaService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Ar areas, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/banks/services/bank.service.go b/internal/modules/master/banks/services/bank.service.go index 83d3029d..dc7ab08d 100644 --- a/internal/modules/master/banks/services/bank.service.go +++ b/internal/modules/master/banks/services/bank.service.go @@ -51,7 +51,7 @@ func (s bankService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Ba banks, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/customers/services/customer.service.go b/internal/modules/master/customers/services/customer.service.go index 12a31441..8804cdd5 100644 --- a/internal/modules/master/customers/services/customer.service.go +++ b/internal/modules/master/customers/services/customer.service.go @@ -3,13 +3,14 @@ package service import ( "errors" "fmt" + "strings" + common "gitlab.com/mbugroup/lti-api.git/internal/common/service" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" m "gitlab.com/mbugroup/lti-api.git/internal/middleware" repository "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/repositories" validation "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/validations" "gitlab.com/mbugroup/lti-api.git/internal/utils" - "strings" "github.com/go-playground/validator/v10" "github.com/gofiber/fiber/v2" @@ -53,7 +54,7 @@ func (s customerService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit customers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/employees/services/employees.service.go b/internal/modules/master/employees/services/employees.service.go index 4998eaec..9e4c194a 100644 --- a/internal/modules/master/employees/services/employees.service.go +++ b/internal/modules/master/employees/services/employees.service.go @@ -53,7 +53,7 @@ func (s employeesService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti employeess, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - db = db.Where("employees.name LIKE ?", "%"+params.Search+"%") + db = db.Where("LOWER(employees.name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.KandangId != nil { db = db.Joins("JOIN employee_kandangs ek ON ek.employee_id = employees.id"). diff --git a/internal/modules/master/fcrs/services/fcr.service.go b/internal/modules/master/fcrs/services/fcr.service.go index f4125374..43a20341 100644 --- a/internal/modules/master/fcrs/services/fcr.service.go +++ b/internal/modules/master/fcrs/services/fcr.service.go @@ -55,7 +55,7 @@ func (s fcrService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Fcr fcrs, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/flocks/services/flock.service.go b/internal/modules/master/flocks/services/flock.service.go index ad086920..2f0130f0 100644 --- a/internal/modules/master/flocks/services/flock.service.go +++ b/internal/modules/master/flocks/services/flock.service.go @@ -52,7 +52,7 @@ func (s flockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.F flocks, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/kandangs/services/kandang.service.go b/internal/modules/master/kandangs/services/kandang.service.go index 35fe2c30..96895c20 100644 --- a/internal/modules/master/kandangs/services/kandang.service.go +++ b/internal/modules/master/kandangs/services/kandang.service.go @@ -3,13 +3,14 @@ package service import ( "errors" "fmt" + "strings" + common "gitlab.com/mbugroup/lti-api.git/internal/common/service" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" m "gitlab.com/mbugroup/lti-api.git/internal/middleware" repository "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/repositories" validation "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/validations" "gitlab.com/mbugroup/lti-api.git/internal/utils" - "strings" "github.com/go-playground/validator/v10" "github.com/gofiber/fiber/v2" @@ -54,7 +55,7 @@ func (s kandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity kandangs, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.LocationId != 0 { db = db.Where("location_id = ?", params.LocationId) diff --git a/internal/modules/master/locations/services/location.service.go b/internal/modules/master/locations/services/location.service.go index 19894d10..8fad74ba 100644 --- a/internal/modules/master/locations/services/location.service.go +++ b/internal/modules/master/locations/services/location.service.go @@ -52,7 +52,7 @@ func (s locationService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit locations, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - db = db.Where("name LIKE ?", "%"+params.Search+"%") + db = db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.AreaId != 0 { db = db.Where("area_id = ?", params.AreaId) diff --git a/internal/modules/master/nonstocks/services/nonstock.service.go b/internal/modules/master/nonstocks/services/nonstock.service.go index 876d4c1e..404d6561 100644 --- a/internal/modules/master/nonstocks/services/nonstock.service.go +++ b/internal/modules/master/nonstocks/services/nonstock.service.go @@ -68,7 +68,7 @@ func (s nonstockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/phase-activities/services/phase-activity.service.go b/internal/modules/master/phase-activities/services/phase-activity.service.go index 24b8272e..a6573a20 100644 --- a/internal/modules/master/phase-activities/services/phase-activity.service.go +++ b/internal/modules/master/phase-activities/services/phase-activity.service.go @@ -56,7 +56,7 @@ func (s phaseActivityService) GetAll(c *fiber.Ctx, params *validation.Query) ([] phaseActivitys, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - db = db.Where("name LIKE ?", "%"+params.Search+"%") + db = db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.PhaseIDs != "" { ids := parseIDs(params.PhaseIDs) diff --git a/internal/modules/master/phasess/services/phases.service.go b/internal/modules/master/phasess/services/phases.service.go index 98e73bef..0054aa25 100644 --- a/internal/modules/master/phasess/services/phases.service.go +++ b/internal/modules/master/phasess/services/phases.service.go @@ -51,7 +51,7 @@ func (s phasesService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity. phasess, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.Category != nil { db = db.Where("category = ?", *params.Category) diff --git a/internal/modules/master/product-categories/services/product-category.service.go b/internal/modules/master/product-categories/services/product-category.service.go index 90936d7b..3f640b4f 100644 --- a/internal/modules/master/product-categories/services/product-category.service.go +++ b/internal/modules/master/product-categories/services/product-category.service.go @@ -52,7 +52,7 @@ func (s productCategoryService) GetAll(c *fiber.Ctx, params *validation.Query) ( productCategories, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/production-standards/services/production-standard.service.go b/internal/modules/master/production-standards/services/production-standard.service.go index 4005b014..0bfa3809 100644 --- a/internal/modules/master/production-standards/services/production-standard.service.go +++ b/internal/modules/master/production-standards/services/production-standard.service.go @@ -63,7 +63,7 @@ func (s productionStandardService) GetAll(c *fiber.Ctx, params *validation.Query productionStandards, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.ProjectCategory != "" { return db.Where("project_category = ?", params.ProjectCategory) diff --git a/internal/modules/master/products/services/product.service.go b/internal/modules/master/products/services/product.service.go index f40d92be..9c3ad96b 100644 --- a/internal/modules/master/products/services/product.service.go +++ b/internal/modules/master/products/services/product.service.go @@ -72,7 +72,7 @@ func (s productService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity db = s.withRelations(db) db = db.Where("is_visible = ?", true) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.ProductCategoryID != 0 { return db.Where("product_category_id = ?", params.ProductCategoryID) diff --git a/internal/modules/master/suppliers/services/supplier.service.go b/internal/modules/master/suppliers/services/supplier.service.go index 75d8fa04..8a81c6df 100644 --- a/internal/modules/master/suppliers/services/supplier.service.go +++ b/internal/modules/master/suppliers/services/supplier.service.go @@ -65,11 +65,11 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit suppliers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.Category != "" { - db = db.Where("category LIKE ?", "%"+params.Category+"%") + db = db.Where("LOWER(category) LIKE LOWER(?)", "%"+params.Category+"%") } return db.Order("created_at DESC").Order("updated_at DESC") diff --git a/internal/modules/master/uoms/services/uom.service.go b/internal/modules/master/uoms/services/uom.service.go index 5396849b..c55c61c9 100644 --- a/internal/modules/master/uoms/services/uom.service.go +++ b/internal/modules/master/uoms/services/uom.service.go @@ -51,7 +51,7 @@ func (s uomService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Uom uoms, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") }) diff --git a/internal/modules/master/warehouses/services/warehouse.service.go b/internal/modules/master/warehouses/services/warehouse.service.go index 79c41284..5401762c 100644 --- a/internal/modules/master/warehouses/services/warehouse.service.go +++ b/internal/modules/master/warehouses/services/warehouse.service.go @@ -3,13 +3,14 @@ package service import ( "errors" "fmt" + "strings" + common "gitlab.com/mbugroup/lti-api.git/internal/common/service" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" m "gitlab.com/mbugroup/lti-api.git/internal/middleware" repository "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories" validation "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/validations" "gitlab.com/mbugroup/lti-api.git/internal/utils" - "strings" "github.com/go-playground/validator/v10" "github.com/gofiber/fiber/v2" @@ -53,7 +54,7 @@ func (s warehouseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti warehouses, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { db = s.withRelations(db) if params.Search != "" { - db = db.Where("warehouses.name LIKE ?", "%"+params.Search+"%") + db = db.Where("LOWER(warehouses.name) LIKE LOWER(?)", "%"+params.Search+"%") } if params.AreaId != 0 { db = db.Where("area_id = ?", params.AreaId) diff --git a/internal/modules/users/services/user.service.go b/internal/modules/users/services/user.service.go index 3b28197e..470bcb38 100644 --- a/internal/modules/users/services/user.service.go +++ b/internal/modules/users/services/user.service.go @@ -45,7 +45,7 @@ func (s userService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Us users, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { if params.Search != "" { - return db.Where("name LIKE ?", "%"+params.Search+"%") + return db.Where("LOWER(name) LIKE LOWER(?)", "%"+params.Search+"%") } return db.Order("created_at DESC").Order("updated_at DESC") })