ch card-orders
This commit is contained in:
BIN
Screenshot 2026-09-30 at 14.12.05.png
Normal file
BIN
Screenshot 2026-09-30 at 14.12.05.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
BIN
Screenshot 2026-09-30 at 14.12.41.png
Normal file
BIN
Screenshot 2026-09-30 at 14.12.41.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 KiB |
@@ -50,6 +50,13 @@ LEFT JOIN users u ON u.id = co.user_id`
|
||||
var cardOrderSelectColumns = shared.PrefixedColumns("co", cardOrderColumns) + `,
|
||||
cs.name, ct.name, b.name, ` + shared.UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
||||
|
||||
const cardOrderListFromClause = cardOrderFromClause + `
|
||||
LEFT JOIN provinces bp ON bp.id = b.province_id`
|
||||
|
||||
var cardOrderListColumns = `co.id, co.unique_id, co.customer_name, co.customer_surname, co.customer_patronic_name,
|
||||
co.phone, co.card_type_id, ct.name, co.card_state_id, cs.name, co.branch_id, b.name, bp.name, co.region,
|
||||
co.passport_serie, co.passport_id, co.user_id, ` + shared.UserDisplaySQL + `, co.status, co.paid, co.created_at`
|
||||
|
||||
func resolveStatus(status *string) *string {
|
||||
if status == nil || strings.TrimSpace(*status) == "" {
|
||||
pending := "pending"
|
||||
@@ -98,7 +105,7 @@ func (r *repository) List(ctx context.Context, filter cardorder.ListFilter) (car
|
||||
offsetPlaceholder := len(args) + 2
|
||||
query := fmt.Sprintf(
|
||||
`SELECT %s%s%s ORDER BY co.id LIMIT $%d OFFSET $%d`,
|
||||
cardOrderSelectColumns, cardOrderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
||||
cardOrderListColumns, cardOrderListFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
||||
)
|
||||
|
||||
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
||||
@@ -107,9 +114,9 @@ func (r *repository) List(ctx context.Context, filter cardorder.ListFilter) (car
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var items []cardorder.CardOrderDTO
|
||||
items := []cardorder.CardOrderListItemDTO{}
|
||||
for rows.Next() {
|
||||
item, err := scanCardOrderWithJoins(rows)
|
||||
item, err := scanCardOrderListItem(rows)
|
||||
if err != nil {
|
||||
return cardorder.ListCardOrderDTO{}, err
|
||||
}
|
||||
@@ -230,6 +237,49 @@ func scanCardOrder(row genericrepo.Scanner) (cardorder.CardOrderDTO, error) {
|
||||
return scanCardOrderRow(row, false)
|
||||
}
|
||||
|
||||
func scanCardOrderListItem(row genericrepo.Scanner) (cardorder.CardOrderListItemDTO, error) {
|
||||
var item cardorder.CardOrderListItemDTO
|
||||
var cardTypeId, cardStateId, branchId int64
|
||||
var userId *int64
|
||||
var cardTypeNameJSON, cardStateNameJSON, branchNameJSON, provinceNameJSON []byte
|
||||
var userName string
|
||||
|
||||
if err := row.Scan(
|
||||
&item.Id, &item.UniqueId, &item.CustomerName, &item.CustomerSurname, &item.CustomerPatronicName,
|
||||
&item.Phone, &cardTypeId, &cardTypeNameJSON, &cardStateId, &cardStateNameJSON, &branchId, &branchNameJSON, &provinceNameJSON, &item.Region,
|
||||
&item.PassportSerie, &item.PassportId, &userId, &userName, &item.Status, &item.Paid, &item.CreatedAt,
|
||||
); err != nil {
|
||||
return cardorder.CardOrderListItemDTO{}, err
|
||||
}
|
||||
|
||||
var cardTypeName, cardStateName, branchName shared.LocalizedText
|
||||
if err := shared.UnmarshalLocalized(cardTypeNameJSON, &cardTypeName); err != nil {
|
||||
return cardorder.CardOrderListItemDTO{}, err
|
||||
}
|
||||
if err := shared.UnmarshalLocalized(cardStateNameJSON, &cardStateName); err != nil {
|
||||
return cardorder.CardOrderListItemDTO{}, err
|
||||
}
|
||||
if err := shared.UnmarshalLocalized(branchNameJSON, &branchName); err != nil {
|
||||
return cardorder.CardOrderListItemDTO{}, err
|
||||
}
|
||||
if err := shared.UnmarshalLocalized(provinceNameJSON, &item.ProvinceName); err != nil {
|
||||
return cardorder.CardOrderListItemDTO{}, err
|
||||
}
|
||||
if cardTypeId != 0 {
|
||||
item.CardType = &shared.NamedInfo{Id: cardTypeId, Name: cardTypeName}
|
||||
}
|
||||
if cardStateId != 0 {
|
||||
item.CardState = &shared.NamedInfo{Id: cardStateId, Name: cardStateName}
|
||||
}
|
||||
if branchId != 0 {
|
||||
item.Branch = &shared.NamedInfo{Id: branchId, Name: branchName}
|
||||
}
|
||||
if userId != nil {
|
||||
item.User = &cardorder.ListUserDTO{Id: *userId, Name: userName}
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func scanCardOrderWithJoins(row genericrepo.Scanner) (cardorder.CardOrderDTO, error) {
|
||||
return scanCardOrderRow(row, true)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,35 @@ type ListFilter struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
type ListCardOrderDTO struct {
|
||||
Count int64 `json:"count"`
|
||||
CardOrders []CardOrderDTO `json:"cardOrders"`
|
||||
// CardOrderListItemDTO is the list row; addresses, passport issue details
|
||||
// and scans come from GET /card-orders/:id.
|
||||
type CardOrderListItemDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueId *string `json:"uniqueId"`
|
||||
CustomerName string `json:"customerName"`
|
||||
CustomerSurname string `json:"customerSurname"`
|
||||
CustomerPatronicName *string `json:"customerPatronicName"`
|
||||
Phone *string `json:"phone"`
|
||||
CardType *shared.NamedInfo `json:"cardType,omitempty"`
|
||||
CardState *shared.NamedInfo `json:"cardState,omitempty"`
|
||||
Branch *shared.NamedInfo `json:"branch,omitempty"`
|
||||
// ProvinceName is the branch's province (etrap).
|
||||
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||
Region string `json:"region"`
|
||||
PassportSerie string `json:"passportSerie"`
|
||||
PassportId string `json:"passportId"`
|
||||
User *ListUserDTO `json:"user,omitempty"`
|
||||
Status *string `json:"status"`
|
||||
Paid bool `json:"paid"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type ListUserDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ListCardOrderDTO struct {
|
||||
Count int64 `json:"count"`
|
||||
CardOrders []CardOrderListItemDTO `json:"cardOrders"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user