ch card-rekwezit
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:20:28 +05:00
parent 15774d2bc4
commit 27ad42528c
5 changed files with 71 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

View File

@@ -49,6 +49,13 @@ LEFT JOIN users u ON u.id = cro.user_id`
var cardRekwizitOrderSelectColumns = shared.PrefixedColumns("cro", cardRekwizitOrderColumns) + `,
ct.name, b.name, ` + shared.UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
const cardRekwizitOrderListFromClause = cardRekwizitOrderFromClause + `
LEFT JOIN provinces bp ON bp.id = b.province_id`
var cardRekwizitOrderListColumns = `cro.id, cro.unique_id, cro.card_type_id, ct.name,
cro.customer_name, cro.customer_surname, cro.user_id, ` + shared.UserDisplaySQL + `,
cro.region, cro.branch_id, b.name, bp.name, cro.status`
func resolveStatus(status *string) *string {
if status == nil || strings.TrimSpace(*status) == "" {
pending := "pending"
@@ -92,7 +99,7 @@ func (r *repository) List(ctx context.Context, filter cardrekwizit.ListFilter) (
offsetPlaceholder := len(args) + 2
query := fmt.Sprintf(
`SELECT %s%s%s ORDER BY cro.id LIMIT $%d OFFSET $%d`,
cardRekwizitOrderSelectColumns, cardRekwizitOrderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
cardRekwizitOrderListColumns, cardRekwizitOrderListFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
)
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
@@ -101,9 +108,9 @@ func (r *repository) List(ctx context.Context, filter cardrekwizit.ListFilter) (
}
defer rows.Close()
var items []cardrekwizit.CardRekwizitOrderDTO
items := []cardrekwizit.CardRekwizitOrderListItemDTO{}
for rows.Next() {
item, err := scanCardRekwizitOrderWithJoins(rows)
item, err := scanCardRekwizitOrderListItem(rows)
if err != nil {
return cardrekwizit.ListCardRekwizitOrderDTO{}, err
}
@@ -217,6 +224,43 @@ func scanCardRekwizitOrder(row genericrepo.Scanner) (cardrekwizit.CardRekwizitOr
return scanCardRekwizitOrderRow(row, false)
}
func scanCardRekwizitOrderListItem(row genericrepo.Scanner) (cardrekwizit.CardRekwizitOrderListItemDTO, error) {
var item cardrekwizit.CardRekwizitOrderListItemDTO
var cardTypeId, branchId int64
var userId *int64
var cardTypeNameJSON, branchNameJSON, provinceNameJSON []byte
var userName string
if err := row.Scan(
&item.Id, &item.UniqueId, &cardTypeId, &cardTypeNameJSON,
&item.CustomerName, &item.CustomerSurname, &userId, &userName,
&item.Region, &branchId, &branchNameJSON, &provinceNameJSON, &item.Status,
); err != nil {
return cardrekwizit.CardRekwizitOrderListItemDTO{}, err
}
var cardTypeName, branchName shared.LocalizedText
if err := shared.UnmarshalLocalized(cardTypeNameJSON, &cardTypeName); err != nil {
return cardrekwizit.CardRekwizitOrderListItemDTO{}, err
}
if err := shared.UnmarshalLocalized(branchNameJSON, &branchName); err != nil {
return cardrekwizit.CardRekwizitOrderListItemDTO{}, err
}
if err := shared.UnmarshalLocalized(provinceNameJSON, &item.ProvinceName); err != nil {
return cardrekwizit.CardRekwizitOrderListItemDTO{}, err
}
if cardTypeId != 0 {
item.CardType = &shared.NamedInfo{Id: cardTypeId, Name: cardTypeName}
}
if branchId != 0 {
item.Branch = &shared.NamedInfo{Id: branchId, Name: branchName}
}
if userId != nil {
item.User = &cardrekwizit.ListUserDTO{Id: *userId, Name: userName}
}
return item, nil
}
func scanCardRekwizitOrderWithJoins(row genericrepo.Scanner) (cardrekwizit.CardRekwizitOrderDTO, error) {
return scanCardRekwizitOrderRow(row, true)
}

View File

@@ -95,7 +95,28 @@ type ListFilter struct {
Limit int
}
type ListCardRekwizitOrderDTO struct {
Count int64 `json:"count"`
CardRekwizitOrders []CardRekwizitOrderDTO `json:"cardRekwizitOrders"`
// CardRekwizitOrderListItemDTO is the list row; card number, passport and
// scans come from GET /card-rekwizit-orders/:id.
type CardRekwizitOrderListItemDTO struct {
Id int64 `json:"id"`
UniqueId *string `json:"uniqueId"`
CardType *shared.NamedInfo `json:"cardType,omitempty"`
CustomerName string `json:"customerName"`
CustomerSurname string `json:"customerSurname"`
User *ListUserDTO `json:"user,omitempty"`
Region string `json:"region"`
Branch *shared.NamedInfo `json:"branch,omitempty"`
// ProvinceName is the branch's province (etrap).
ProvinceName shared.LocalizedText `json:"provinceName"`
Status *string `json:"status"`
}
type ListUserDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type ListCardRekwizitOrderDTO struct {
Count int64 `json:"count"`
CardRekwizitOrders []CardRekwizitOrderListItemDTO `json:"cardRekwizitOrders"`
}