ch card-rekwezit
This commit is contained in:
1 parent
15774d2bc4
commit
27ad42528c
5 files changed
+71
-6
No files matched your search
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 |
@@ -49,6 +49,13 @@ LEFT JOIN users u ON u.id = cro.user_id`
|
|||||||
var cardRekwizitOrderSelectColumns = shared.PrefixedColumns("cro", cardRekwizitOrderColumns) + `,
|
var cardRekwizitOrderSelectColumns = shared.PrefixedColumns("cro", cardRekwizitOrderColumns) + `,
|
||||||
ct.name, b.name, ` + shared.UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
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 {
|
func resolveStatus(status *string) *string {
|
||||||
if status == nil || strings.TrimSpace(*status) == "" {
|
if status == nil || strings.TrimSpace(*status) == "" {
|
||||||
pending := "pending"
|
pending := "pending"
|
||||||
@@ -92,7 +99,7 @@ func (r *repository) List(ctx context.Context, filter cardrekwizit.ListFilter) (
|
|||||||
offsetPlaceholder := len(args) + 2
|
offsetPlaceholder := len(args) + 2
|
||||||
query := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
`SELECT %s%s%s ORDER BY cro.id LIMIT $%d OFFSET $%d`,
|
`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)...)
|
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()
|
defer rows.Close()
|
||||||
|
|
||||||
var items []cardrekwizit.CardRekwizitOrderDTO
|
items := []cardrekwizit.CardRekwizitOrderListItemDTO{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
item, err := scanCardRekwizitOrderWithJoins(rows)
|
item, err := scanCardRekwizitOrderListItem(rows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cardrekwizit.ListCardRekwizitOrderDTO{}, err
|
return cardrekwizit.ListCardRekwizitOrderDTO{}, err
|
||||||
}
|
}
|
||||||
@@ -217,6 +224,43 @@ func scanCardRekwizitOrder(row genericrepo.Scanner) (cardrekwizit.CardRekwizitOr
|
|||||||
return scanCardRekwizitOrderRow(row, false)
|
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) {
|
func scanCardRekwizitOrderWithJoins(row genericrepo.Scanner) (cardrekwizit.CardRekwizitOrderDTO, error) {
|
||||||
return scanCardRekwizitOrderRow(row, true)
|
return scanCardRekwizitOrderRow(row, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,28 @@ type ListFilter struct {
|
|||||||
Limit int
|
Limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCardRekwizitOrderDTO struct {
|
// CardRekwizitOrderListItemDTO is the list row; card number, passport and
|
||||||
Count int64 `json:"count"`
|
// scans come from GET /card-rekwizit-orders/:id.
|
||||||
CardRekwizitOrders []CardRekwizitOrderDTO `json:"cardRekwizitOrders"`
|
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"`
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user