Accept flexible loan payloads and nest related info on lending responses.
Widen loan_orders.region in the init migration and share common relation helpers across loan APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0098422798
commit
6683826662
13 files changed
+591
-346
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type NamedInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name LocalizedText `json:"name"`
|
||||
}
|
||||
|
||||
// TextInfo is for catalog rows whose name is a plain string (not localized JSON).
|
||||
type TextInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type BranchInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name LocalizedText `json:"name"`
|
||||
UniqueCode string `json:"uniqueCode,omitempty"`
|
||||
}
|
||||
|
||||
const UserDisplaySQL = `COALESCE(NULLIF(TRIM(CONCAT_WS(' ', u.first_name, u.last_name)), ''), NULLIF(u.name, ''), u.username, '')`
|
||||
|
||||
const UserInfoSQL = 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, ", ")
|
||||
}
|
||||
|
||||
func UnmarshalLocalized(raw []byte, dest *LocalizedText) error {
|
||||
if len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := json.Unmarshal(raw, dest); err != nil {
|
||||
*dest = LocalizedText{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user