Enrich cards API responses with joined relations and share common helpers.
Nest user/branch/cardType/cardState on card, order, pin-order, and visa-master reads; accept flexible dates/IDs on pin create; widen pin region; ignore undefined list query params; extract internal/cards/shared to remove duplicated types and helpers. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1fd0abbcb2
commit
0098422798
27 files changed
+942
-777
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"online-back/internal/cards/shared"
|
||||
"online-back/internal/cards/visamaster"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/pkg/client/postgresql"
|
||||
@@ -27,8 +28,6 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) visamaster.
|
||||
}
|
||||
}
|
||||
|
||||
const userDisplaySQL = `COALESCE(NULLIF(TRIM(CONCAT_WS(' ', u.first_name, u.last_name)), ''), NULLIF(u.name, ''), u.username, '')`
|
||||
|
||||
const orderFromClause = ` FROM visa_master_payment_orders o
|
||||
LEFT JOIN branches b ON b.id = o.branch_id
|
||||
LEFT JOIN users u ON u.id = o.user_id
|
||||
@@ -50,15 +49,7 @@ var orderColumnsSQL = strings.Join(orderColumns, ", ")
|
||||
|
||||
var orderWritableColumnsSQL = strings.Join(orderWritableColumns, ", ")
|
||||
|
||||
var orderSelectColumns = prefixedColumns("o", orderColumns) + `, p.region, b.name, COALESCE(b.unique_code, ''), COALESCE(b.region, ''), b.province_id, p.name, ` + userDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
||||
|
||||
func prefixedColumns(alias string, cols []string) string {
|
||||
parts := make([]string, len(cols))
|
||||
for i, col := range cols {
|
||||
parts[i] = alias + "." + col
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
var orderSelectColumns = shared.PrefixedColumns("o", orderColumns) + `, p.region, b.name, COALESCE(b.unique_code, ''), COALESCE(b.region, ''), b.province_id, p.name, ` + shared.UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
||||
|
||||
func resolveStatus(status *string) *string {
|
||||
if status == nil || strings.TrimSpace(*status) == "" {
|
||||
@@ -282,18 +273,18 @@ func scanOrder(row genericrepo.Scanner) (visamaster.VisaMasterPaymentOrderDTO, e
|
||||
|
||||
item.Branch.Id = item.BranchId
|
||||
item.Branch.Region = branchRegion
|
||||
if err := unmarshalLocalized(regionNameJSON, &item.RegionName); err != nil {
|
||||
if err := shared.UnmarshalLocalized(regionNameJSON, &item.RegionName); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderDTO{}, err
|
||||
}
|
||||
if err := unmarshalLocalized(branchNameJSON, &item.Branch.Name); err != nil {
|
||||
if err := shared.UnmarshalLocalized(branchNameJSON, &item.Branch.Name); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderDTO{}, err
|
||||
}
|
||||
if err := unmarshalLocalized(provinceNameJSON, &item.Branch.ProvinceName); err != nil {
|
||||
if err := shared.UnmarshalLocalized(provinceNameJSON, &item.Branch.ProvinceName); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderDTO{}, err
|
||||
}
|
||||
|
||||
if item.UserId != nil {
|
||||
item.User = &visamaster.UserInfo{
|
||||
item.User = &shared.UserInfo{
|
||||
Id: *item.UserId,
|
||||
Name: userName,
|
||||
Username: userUsername,
|
||||
@@ -311,10 +302,3 @@ func jsonOrDefault(raw []byte, fallback string) json.RawMessage {
|
||||
}
|
||||
return json.RawMessage(raw)
|
||||
}
|
||||
|
||||
func unmarshalLocalized(raw []byte, dest *visamaster.LocalizedText) error {
|
||||
if len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(raw, dest)
|
||||
}
|
||||
Reference in new issue
Block a user