ch pin-orders
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 154 KiB |
BIN
Screenshot 2026-09-30 at 14.22.23.png
Normal file
BIN
Screenshot 2026-09-30 at 14.22.23.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 KiB |
@@ -78,8 +78,12 @@ func (r *repository) List(ctx context.Context, filter cardpinorders.ListFilter)
|
|||||||
limitPlaceholder := len(args) + 1
|
limitPlaceholder := len(args) + 1
|
||||||
offsetPlaceholder := len(args) + 2
|
offsetPlaceholder := len(args) + 2
|
||||||
query := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
`SELECT %s%s%s ORDER BY cpo.id LIMIT $%d OFFSET $%d`,
|
`SELECT cpo.id, cpo.unique_id, cpo.card_number, cpo.customer_name, cpo.customer_surname,
|
||||||
cardPinOrderSelectColumns, cardPinOrderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
cpo.region, bp.name, cpo.phone, cpo.status, cpo.created_at
|
||||||
|
FROM card_pin_orders cpo
|
||||||
|
LEFT JOIN branches b ON b.id = cpo.branch_id
|
||||||
|
LEFT JOIN provinces bp ON bp.id = b.province_id%s ORDER BY cpo.id LIMIT $%d OFFSET $%d`,
|
||||||
|
whereClause, limitPlaceholder, offsetPlaceholder,
|
||||||
)
|
)
|
||||||
|
|
||||||
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
||||||
@@ -88,10 +92,17 @@ func (r *repository) List(ctx context.Context, filter cardpinorders.ListFilter)
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var items []cardpinorders.CardPinOrderDTO
|
items := []cardpinorders.CardPinOrderListItemDTO{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
item, err := scanCardPinOrderWithJoins(rows)
|
var item cardpinorders.CardPinOrderListItemDTO
|
||||||
if err != nil {
|
var provinceNameJSON []byte
|
||||||
|
if err := rows.Scan(
|
||||||
|
&item.Id, &item.UniqueId, &item.CardNumber, &item.CustomerName, &item.CustomerSurname,
|
||||||
|
&item.Region, &provinceNameJSON, &item.Phone, &item.Status, &item.CreatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return cardpinorders.ListCardPinOrderDTO{}, err
|
||||||
|
}
|
||||||
|
if err := shared.UnmarshalLocalized(provinceNameJSON, &item.ProvinceName); err != nil {
|
||||||
return cardpinorders.ListCardPinOrderDTO{}, err
|
return cardpinorders.ListCardPinOrderDTO{}, err
|
||||||
}
|
}
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
|
|||||||
@@ -89,7 +89,23 @@ type ListFilter struct {
|
|||||||
Limit int
|
Limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCardPinOrderDTO struct {
|
// CardPinOrderListItemDTO is the list row; card type, branch, passport and
|
||||||
Count int64 `json:"count"`
|
// scans come from GET /card-pin-orders/:id.
|
||||||
CardPinOrders []CardPinOrderDTO `json:"cardPinOrders"`
|
type CardPinOrderListItemDTO struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
UniqueId *string `json:"uniqueId"`
|
||||||
|
CardNumber *string `json:"cardNumber"`
|
||||||
|
CustomerName string `json:"customerName"`
|
||||||
|
CustomerSurname string `json:"customerSurname"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
// ProvinceName is the branch's province (etrap).
|
||||||
|
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||||
|
Phone *string `json:"phone"`
|
||||||
|
Status *string `json:"status"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListCardPinOrderDTO struct {
|
||||||
|
Count int64 `json:"count"`
|
||||||
|
CardPinOrders []CardPinOrderListItemDTO `json:"cardPinOrders"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user