From d536036772bd59688108c4096662cc372c59b9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20devkcud=20Albanese?= Date: Sat, 2 Nov 2024 19:16:22 -0300 Subject: [PATCH] fix: Add regex prepare name for search in user and component --- internal/service/repository/component.go | 8 +++++++- internal/service/repository/user.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/service/repository/component.go b/internal/service/repository/component.go index 3c02265..5716675 100644 --- a/internal/service/repository/component.go +++ b/internal/service/repository/component.go @@ -488,7 +488,13 @@ func (cr *componentRepository) Search(issuerID uint, search *dto.SearchComponent regexp_like(u.first_name, ?, 'i') OR regexp_like(u.last_name, ?, 'i') OR regexp_like(u.username, ?, 'i') - )`, *search.Name, *search.Name, *search.Name, *search.Name, *search.Name) + )`, + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + ) // TODO: Create ranking system } diff --git a/internal/service/repository/user.go b/internal/service/repository/user.go index 584f7c9..8716e6d 100644 --- a/internal/service/repository/user.go +++ b/internal/service/repository/user.go @@ -6,6 +6,7 @@ import ( "github.com/swibly/swibly-api/pkg/aws" "github.com/swibly/swibly-api/pkg/db" "github.com/swibly/swibly-api/pkg/pagination" + "github.com/swibly/swibly-api/pkg/utils" "gorm.io/gorm" ) @@ -88,7 +89,12 @@ func (u userRepository) Search(issuerID uint, search *dto.SearchUser, page, perp Where("show_profile = TRUE") if search.Name != nil { - query = query.Where("regexp_like(first_name, ?, 'i') OR regexp_like(last_name, ?, 'i') OR regexp_like(username, ?, 'i')", *search.Name, *search.Name, *search.Name) + query = query.Where( + "regexp_like(first_name, ?, 'i') OR regexp_like(last_name, ?, 'i') OR regexp_like(username, ?, 'i')", + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + utils.RegexPrepareName(*search.Name), + ) // TODO: Create ranking system }