Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
fix: Add regex prepare name for search in user and component
Browse files Browse the repository at this point in the history
  • Loading branch information
devkcud committed Nov 2, 2024
1 parent 96de5f8 commit d536036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion internal/service/repository/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion internal/service/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d536036

Please sign in to comment.