ch data
Some checks failed
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:
2026-09-30 13:55:49 +05:00
parent 4f3631c70d
commit 68ead82827
4 changed files with 53 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@@ -34,6 +34,13 @@ LEFT JOIN users u ON u.id = lo.user_id
LEFT JOIN provinces p ON p.id = lo.work_province_id
LEFT JOIN loan_order_required_docs d ON d.id = lo.loan_order_required_doc_id`
const loanOrderListFromClause = ` FROM loan_orders lo
LEFT JOIN loan_types lt ON lt.id = lo.loan_type
LEFT JOIN branches b ON b.id = lo.branch_id`
const loanOrderListColumns = `lo.id, lo.loan_type, lt.name, lo.created_at, lo.region,
lo.branch_id, b.name, lo.customer_name, lo.customer_surname, lo.phone, lo.status`
// loanOrderWritableColumns lists every loan_orders column except id, created_at and
// updated_at, in the exact order CreateLoanOrderDTO/UpdateLoanOrderDTO fields are read.
var loanOrderWritableColumns = []string{
@@ -125,7 +132,7 @@ func (r *repository) List(ctx context.Context, filter loanorders.ListFilter) (lo
offsetPlaceholder := len(args) + 2
query := fmt.Sprintf(
`SELECT %s%s%s ORDER BY lo.id DESC LIMIT $%d OFFSET $%d`,
loanOrderSelectColumns, loanOrderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
loanOrderListColumns, loanOrderListFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
)
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
@@ -134,9 +141,9 @@ func (r *repository) List(ctx context.Context, filter loanorders.ListFilter) (lo
}
defer rows.Close()
var items []loanorders.LoanOrderDTO
items := []loanorders.LoanOrderListItemDTO{}
for rows.Next() {
item, err := scanLoanOrder(rows)
item, err := scanLoanOrderListItem(rows)
if err != nil {
return loanorders.ListLoanOrderDTO{}, err
}
@@ -274,6 +281,32 @@ func (r *repository) Delete(ctx context.Context, id int64) error {
return r.generic.Delete(ctx, id)
}
func scanLoanOrderListItem(row genericrepo.Scanner) (loanorders.LoanOrderListItemDTO, error) {
var item loanorders.LoanOrderListItemDTO
var loanTypeId, branchId int64
var loanTypeNameJSON, branchNameJSON []byte
err := row.Scan(
&item.Id, &loanTypeId, &loanTypeNameJSON, &item.CreatedAt, &item.Region,
&branchId, &branchNameJSON, &item.CustomerName, &item.CustomerSurname, &item.Phone, &item.Status,
)
if err != nil {
return loanorders.LoanOrderListItemDTO{}, err
}
var loanTypeName, branchName shared.LocalizedText
_ = shared.UnmarshalLocalized(loanTypeNameJSON, &loanTypeName)
_ = shared.UnmarshalLocalized(branchNameJSON, &branchName)
if loanTypeId != 0 {
item.LoanType = &shared.NamedInfo{Id: loanTypeId, Name: loanTypeName}
}
if branchId != 0 {
item.Branch = &shared.NamedInfo{Id: branchId, Name: branchName}
}
return item, nil
}
func scanLoanOrder(row genericrepo.Scanner) (loanorders.LoanOrderDTO, error) {
var item loanorders.LoanOrderDTO
var loanTypeNameJSON, branchNameJSON, provinceNameJSON []byte

View File

@@ -233,7 +233,21 @@ type ListFilter struct {
Limit int
}
type ListLoanOrderDTO struct {
Count int64 `json:"count"`
LoanOrders []LoanOrderDTO `json:"loanOrders"`
// LoanOrderListItemDTO is the list row; passport, work, card and guarantor
// details come from GET /loan-orders/:id.
type LoanOrderListItemDTO struct {
Id int64 `json:"id"`
LoanType *shared.NamedInfo `json:"loanType,omitempty"`
CreatedAt time.Time `json:"createdAt"`
Region string `json:"region"`
Branch *shared.NamedInfo `json:"branch,omitempty"`
CustomerName string `json:"customerName"`
CustomerSurname string `json:"customerSurname"`
Phone string `json:"phone"`
Status *string `json:"status"`
}
type ListLoanOrderDTO struct {
Count int64 `json:"count"`
LoanOrders []LoanOrderListItemDTO `json:"loanOrders"`
}