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 14:28:52 +05:00
parent 0de3900ed1
commit 3b33e25703
2 changed files with 53 additions and 7 deletions

View File

@@ -109,8 +109,12 @@ func (r *repository) List(ctx context.Context, filter visamaster.ListFilter) (vi
limitPlaceholder := len(args) + 1
offsetPlaceholder := len(args) + 2
query := fmt.Sprintf(
`SELECT %s%s%s ORDER BY o.id DESC LIMIT $%d OFFSET $%d`,
orderSelectColumns, orderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
`SELECT o.id, o.type, o.created_at, o.region, o.branch_id, b.name, p.name,
o.passport_name, o.passport_surname, o.phone, o.status, o.paid
FROM visa_master_payment_orders o
LEFT JOIN branches b ON b.id = o.branch_id
LEFT JOIN provinces p ON p.id = b.province_id%s ORDER BY o.id DESC LIMIT $%d OFFSET $%d`,
whereClause, limitPlaceholder, offsetPlaceholder,
)
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
@@ -119,9 +123,9 @@ func (r *repository) List(ctx context.Context, filter visamaster.ListFilter) (vi
}
defer rows.Close()
var items []visamaster.VisaMasterPaymentOrderDTO
items := []visamaster.VisaMasterPaymentOrderListItemDTO{}
for rows.Next() {
item, err := scanOrder(rows)
item, err := scanOrderListItem(rows)
if err != nil {
return visamaster.ListVisaMasterPaymentOrderDTO{}, err
}
@@ -291,3 +295,28 @@ func jsonOrDefault(raw []byte, fallback string) json.RawMessage {
}
return json.RawMessage(raw)
}
func scanOrderListItem(row genericrepo.Scanner) (visamaster.VisaMasterPaymentOrderListItemDTO, error) {
var item visamaster.VisaMasterPaymentOrderListItemDTO
var branchId int64
var branchNameJSON, provinceNameJSON []byte
if err := row.Scan(
&item.Id, &item.Type, &item.CreatedAt, &item.Region, &branchId, &branchNameJSON, &provinceNameJSON,
&item.PassportName, &item.PassportSurname, &item.Phone, &item.Status, &item.Paid,
); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
}
var branchName shared.LocalizedText
if err := shared.UnmarshalLocalized(branchNameJSON, &branchName); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
}
if err := shared.UnmarshalLocalized(provinceNameJSON, &item.ProvinceName); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
}
if branchId != 0 {
item.Branch = &shared.NamedInfo{Id: branchId, Name: branchName}
}
return item, nil
}

View File

@@ -117,7 +117,24 @@ type ListFilter struct {
Limit int
}
type ListVisaMasterPaymentOrderDTO struct {
Count int64 `json:"count"`
VisaMasterPaymentOrders []VisaMasterPaymentOrderDTO `json:"visaMasterPaymentOrders"`
// VisaMasterPaymentOrderListItemDTO is the list row (visa/master and sber);
// sender, receiver, documents and amounts come from GET /visa-master-payment-orders/:id.
type VisaMasterPaymentOrderListItemDTO struct {
Id int64 `json:"id"`
Type *string `json:"type"`
CreatedAt time.Time `json:"createdAt"`
Region string `json:"region"`
Branch *shared.NamedInfo `json:"branch,omitempty"`
// ProvinceName is the branch's province (etrap).
ProvinceName shared.LocalizedText `json:"provinceName"`
PassportName string `json:"passportName"`
PassportSurname string `json:"passportSurname"`
Phone string `json:"phone"`
Status *string `json:"status"`
Paid bool `json:"paid"`
}
type ListVisaMasterPaymentOrderDTO struct {
Count int64 `json:"count"`
VisaMasterPaymentOrders []VisaMasterPaymentOrderListItemDTO `json:"visaMasterPaymentOrders"`
}