Add province-scoped branches for loan paid letters and harden loans.user_id.
Expose GET /loan-paid-off-letters/branches?province_id= for form pickers, require loans.user_id, and proxy the Vite frontend under /online/. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1987d4f596
commit
5f6ddc5217
14 files changed
+172
-343
No files matched your search
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -80,6 +81,14 @@ func buildListQuery(filter loanpaidletter.ListFilter) (whereClause string, args
|
||||
conditions = append(conditions, fmt.Sprintf("passport_id ILIKE $%d", len(args)))
|
||||
}
|
||||
|
||||
if filter.Name != "" {
|
||||
args = append(args, likePattern(filter.Name))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
customer_name ILIKE $%[1]d OR customer_surname ILIKE $%[1]d OR COALESCE(customer_patronic_name, '') ILIKE $%[1]d
|
||||
)`, n))
|
||||
}
|
||||
|
||||
if filter.Status != nil {
|
||||
args = append(args, *filter.Status)
|
||||
conditions = append(conditions, fmt.Sprintf("status = $%d", len(args)))
|
||||
@@ -109,6 +118,46 @@ func likePattern(term string) string {
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) ListBranchesByProvince(ctx context.Context, provinceID int64, activeOnly bool) (loanpaidletter.ListBranchesByProvinceDTO, error) {
|
||||
args := []interface{}{provinceID}
|
||||
where := ` WHERE province_id = $1`
|
||||
if activeOnly {
|
||||
where += ` AND active = true`
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT id, COALESCE(unique_code, ''), name, region, province_id, active
|
||||
FROM branches` + where + `
|
||||
ORDER BY name->>'tm', name->>'en', id`
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
if err != nil {
|
||||
return loanpaidletter.ListBranchesByProvinceDTO{}, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
branches := make([]loanpaidletter.BranchByProvinceDTO, 0)
|
||||
for rows.Next() {
|
||||
var item loanpaidletter.BranchByProvinceDTO
|
||||
var nameJSON []byte
|
||||
if err := rows.Scan(&item.Id, &item.UniqueCode, &nameJSON, &item.Region, &item.ProvinceId, &item.Active); err != nil {
|
||||
return loanpaidletter.ListBranchesByProvinceDTO{}, err
|
||||
}
|
||||
if err := json.Unmarshal(nameJSON, &item.Name); err != nil {
|
||||
return loanpaidletter.ListBranchesByProvinceDTO{}, err
|
||||
}
|
||||
branches = append(branches, item)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return loanpaidletter.ListBranchesByProvinceDTO{}, err
|
||||
}
|
||||
|
||||
return loanpaidletter.ListBranchesByProvinceDTO{
|
||||
Count: int64(len(branches)),
|
||||
Branches: branches,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (loanpaidletter.LoanPaidLetterDTO, error) {
|
||||
return r.generic.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user