Skip to content

Commit

Permalink
Update search queries to use ILIKE for case-insensitive matching in p…
Browse files Browse the repository at this point in the history
…aginated repository methods
  • Loading branch information
IlhamSetiaji committed Dec 24, 2024
1 parent 5163fe2 commit 65cc708
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/repository/employee_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *EmployeeRepository) FindAllPaginated(page int, pageSize int, search str
query := r.DB.Preload("EmployeeJob").Preload("User").Preload("Organization")

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&employees).Error; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/job_level_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *JobLevelRepository) FindAllPaginated(page int, pageSize int, search str
query := r.DB.Preload("OrganizationStructures")

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&jobLevels).Error; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/job_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *JobRepository) FindAllPaginated(page int, pageSize int, search string,
query := r.DB.Preload("OrganizationStructure.Organization").Preload("OrganizationStructure.JobLevel")

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if len(orgStructureIds) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/organization_location_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *OrganizationLocationRepository) FindAllPaginated(page int, pageSize int
}

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

err := query.Count(&total).Error
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/organization_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *OrganizationRepository) FindAllPaginated(page int, pageSize int, search
query := r.DB.Preload("OrganizationLocations").Preload("OrganizationStructures").Preload("OrganizationType")

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&organizations).Error; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/organization_structure_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *OrganizationStructureRepository) FindAllPaginated(page int, pageSize in
query := r.DB.Preload("Organization.OrganizationType").Preload("JobLevel")

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&organizationStructures).Error; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/organization_type_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *OrganizationTypeRepository) FindAllPaginated(page int, pageSize int, se
query := r.DB

if search != "" {
query = query.Where("name LIKE ?", "%"+search+"%")
query = query.Where("name ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&organizationTypes).Error; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *UserRepository) FindAllPaginated(page int, pageSize int, search string)
query := r.DB.Preload("Employee.Organization").Preload("Employee.EmployeeJob.Job").Preload("Employee.EmployeeJob.EmpOrganization").Preload("Employee.EmployeeJob.OrganizationLocation")

if search != "" {
query = query.Where("email LIKE ?", "%"+search+"%").Or("name LIKE ?", "%"+search+"%").Or("username LIKE ?", "%"+search+"%")
query = query.Where("email ILIKE ?", "%"+search+"%").Or("name ILIKE ?", "%"+search+"%").Or("username ILIKE ?", "%"+search+"%")
}

if err := query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&users).Error; err != nil {
Expand Down

0 comments on commit 65cc708

Please sign in to comment.