ch some
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/org/branches"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -105,7 +106,7 @@ func buildListQuery(filter branches.ListFilter) (whereClause string, args []inte
|
||||
}
|
||||
|
||||
if filter.ProvinceName != "" {
|
||||
args = append(args, likePattern(filter.ProvinceName))
|
||||
args = append(args, shared.LikePattern(filter.ProvinceName))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
p.name->>'en' ILIKE $%[1]d OR p.name->>'ru' ILIKE $%[1]d OR p.name->>'tm' ILIKE $%[1]d
|
||||
@@ -113,7 +114,7 @@ func buildListQuery(filter branches.ListFilter) (whereClause string, args []inte
|
||||
}
|
||||
|
||||
if filter.BranchName != "" {
|
||||
args = append(args, likePattern(filter.BranchName))
|
||||
args = append(args, shared.LikePattern(filter.BranchName))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
b.name->>'en' ILIKE $%[1]d OR b.name->>'ru' ILIKE $%[1]d OR b.name->>'tm' ILIKE $%[1]d
|
||||
@@ -121,7 +122,7 @@ func buildListQuery(filter branches.ListFilter) (whereClause string, args []inte
|
||||
}
|
||||
|
||||
if filter.UniqueCode != "" {
|
||||
args = append(args, likePattern(filter.UniqueCode))
|
||||
args = append(args, shared.LikePattern(filter.UniqueCode))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf("b.unique_code ILIKE $%d", n))
|
||||
}
|
||||
@@ -137,13 +138,6 @@ func buildListQuery(filter branches.ListFilter) (whereClause string, args []inte
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (branches.BranchDTO, error) {
|
||||
query := fmt.Sprintf(`SELECT %s%s WHERE b.id = $1`, branchSelectColumns, branchFromClause)
|
||||
row := r.client.QueryRow(ctx, query, id)
|
||||
|
||||
Reference in New Issue
Block a user