ch some
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
guwandyk committed 2026-09-04 19:33:26 +05:00
1 parent 28509eb4ca
commit d1a6fcaadc
102 files changed
+2089 -1957

No files matched your search

+3 -17
View File
@@ -7,6 +7,7 @@ import (
"strings"
"online-back/internal/currency"
"online-back/internal/shared"
"online-back/pkg/client/postgresql"
"online-back/pkg/logging"
"online-back/pkg/repository/genericrepo"
@@ -41,18 +42,10 @@ const currencyFromClause = ` FROM currencies c
LEFT JOIN users cu ON cu.id = c.created_by
LEFT JOIN users uu ON uu.id = c.updated_by`
var currencySelectColumns = prefixed("c", currencyColumns) + `,
var currencySelectColumns = shared.PrefixedColumns("c", currencyColumns) + `,
` + fmt.Sprintf(userDisplaySQL, "cu", "cu", "cu", "cu") + `, COALESCE(cu.username, ''), COALESCE(cu.phone, ''), COALESCE(cu.email, ''),
` + fmt.Sprintf(userDisplaySQL, "uu", "uu", "uu", "uu") + `, COALESCE(uu.username, ''), COALESCE(uu.phone, ''), COALESCE(uu.email, '')`
func prefixed(alias string, cols []string) string {
parts := make([]string, len(cols))
for i, col := range cols {
parts[i] = alias + "." + col
}
return strings.Join(parts, ", ")
}
func (r *repository) List(ctx context.Context, filter currency.ListFilter) (currency.ListCurrencyDTO, error) {
whereClause, args := buildListQuery(filter)
@@ -94,7 +87,7 @@ func buildListQuery(filter currency.ListFilter) (whereClause string, args []inte
var conditions []string
if filter.Search != "" {
args = append(args, likePattern(filter.Search))
args = append(args, shared.LikePattern(filter.Search))
n := len(args)
conditions = append(conditions, fmt.Sprintf(`(
c.currency_from ILIKE $%[1]d ESCAPE '\' OR c.currency_to ILIKE $%[1]d ESCAPE '\'
@@ -117,13 +110,6 @@ func buildListQuery(filter currency.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) (currency.CurrencyDTO, error) {
query := `SELECT ` + currencySelectColumns + currencyFromClause + ` WHERE c.id = $1`
return scanCurrencyWithUsers(r.client.QueryRow(ctx, query, id))