Also accept flexible card-order form values, move mock seed under db/mock, and regenerate Swagger. Co-authored-by: Cursor <cursoragent@cursor.com>
227 lines
8.3 KiB
Go
227 lines
8.3 KiB
Go
package cardorder
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type FlexibleTime time.Time
|
|
|
|
func (t FlexibleTime) Time() time.Time { return time.Time(t) }
|
|
|
|
func (t FlexibleTime) IsZero() bool { return time.Time(t).IsZero() }
|
|
|
|
func (t FlexibleTime) MarshalJSON() ([]byte, error) {
|
|
return time.Time(t).MarshalJSON()
|
|
}
|
|
|
|
func (t *FlexibleTime) UnmarshalJSON(b []byte) error {
|
|
*t = FlexibleTime{}
|
|
raw := strings.TrimSpace(string(b))
|
|
if raw == "" || raw == "null" {
|
|
return nil
|
|
}
|
|
|
|
var n json.Number
|
|
if err := json.Unmarshal(b, &n); err == nil {
|
|
s := n.String()
|
|
if parsed, ok := parseFlexibleTime(s); ok {
|
|
*t = parsed
|
|
return nil
|
|
}
|
|
if unix, err := n.Int64(); err == nil && unix > 0 {
|
|
*t = FlexibleTime(time.Unix(unix, 0).UTC())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return nil
|
|
}
|
|
if parsed, ok := parseFlexibleTime(s); ok {
|
|
*t = parsed
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseFlexibleTime(s string) (FlexibleTime, bool) {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
return FlexibleTime{}, false
|
|
}
|
|
switch strings.ToLower(s) {
|
|
case "string", "undefined", "null", "none", "invalid", "nan", "-":
|
|
return FlexibleTime{}, false
|
|
}
|
|
for _, layout := range []string{
|
|
time.RFC3339Nano,
|
|
time.RFC3339,
|
|
"2006-01-02T15:04:05Z07:00",
|
|
"2006-01-02T15:04:05.000Z",
|
|
"2006-01-02T15:04:05",
|
|
"2006-01-02 15:04:05",
|
|
"2006-01-02",
|
|
"02.01.2006",
|
|
"02/01/2006",
|
|
"02-01-2006",
|
|
"2006/01/02",
|
|
"20060102",
|
|
} {
|
|
if parsed, err := time.Parse(layout, s); err == nil {
|
|
return FlexibleTime(parsed), true
|
|
}
|
|
}
|
|
return FlexibleTime{}, false
|
|
}
|
|
|
|
type FlexibleInt64 int64
|
|
|
|
func (n FlexibleInt64) Int64() int64 { return int64(n) }
|
|
|
|
func (n *FlexibleInt64) UnmarshalJSON(b []byte) error {
|
|
if string(b) == "null" {
|
|
*n = 0
|
|
return nil
|
|
}
|
|
|
|
var v int64
|
|
if err := json.Unmarshal(b, &v); err == nil {
|
|
*n = FlexibleInt64(v)
|
|
return nil
|
|
}
|
|
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return err
|
|
}
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
*n = 0
|
|
return nil
|
|
}
|
|
v, err := strconv.ParseInt(s, 10, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*n = FlexibleInt64(v)
|
|
return nil
|
|
}
|
|
|
|
type CardOrderDTO struct {
|
|
Id int64 `json:"id"`
|
|
UniqueId *string `json:"uniqueId"`
|
|
CardStateId int64 `json:"cardStateId"`
|
|
CardTypeId int64 `json:"cardTypeId"`
|
|
Region string `json:"region"`
|
|
BranchId int64 `json:"branchId"`
|
|
CustomerName string `json:"customerName"`
|
|
CustomerSurname string `json:"customerSurname"`
|
|
CustomerPatronicName *string `json:"customerPatronicName"`
|
|
BornAt *time.Time `json:"bornAt"`
|
|
OldSurname *string `json:"oldSurname"`
|
|
Citizenship string `json:"citizenship"`
|
|
PassportSerie string `json:"passportSerie"`
|
|
PassportId string `json:"passportId"`
|
|
PassportGivenAt time.Time `json:"passportGivenAt"`
|
|
PassportGivenBy string `json:"passportGivenBy"`
|
|
BornPlace string `json:"bornPlace"`
|
|
JobLocation *string `json:"jobLocation"`
|
|
PassportAddress *string `json:"passportAddress"`
|
|
RealAddress *string `json:"realAddress"`
|
|
Phone *string `json:"phone"`
|
|
PhoneAdditional *string `json:"phoneAdditional"`
|
|
Status *string `json:"status"`
|
|
PassportOne string `json:"passportOne"`
|
|
PassportTwo string `json:"passportTwo"`
|
|
PassportThree string `json:"passportThree"`
|
|
PassportFour string `json:"passportFour"`
|
|
Notes *string `json:"notes"`
|
|
UserId *int64 `json:"userId"`
|
|
Paid bool `json:"paid"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
}
|
|
|
|
type CreateCardOrderDTO struct {
|
|
UniqueId *string `json:"uniqueId"`
|
|
CardStateId FlexibleInt64 `json:"cardStateId" binding:"required" swaggertype:"integer"`
|
|
CardTypeId FlexibleInt64 `json:"cardTypeId" binding:"required" swaggertype:"integer"`
|
|
Region string `json:"region" binding:"required"`
|
|
BranchId FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
|
CustomerName string `json:"customerName" binding:"required"`
|
|
CustomerSurname string `json:"customerSurname" binding:"required"`
|
|
CustomerPatronicName *string `json:"customerPatronicName"`
|
|
BornAt *FlexibleTime `json:"bornAt" swaggertype:"string" format:"date"`
|
|
OldSurname *string `json:"oldSurname"`
|
|
Citizenship string `json:"citizenship" binding:"required"`
|
|
PassportSerie string `json:"passportSerie" binding:"required"`
|
|
PassportId string `json:"passportId" binding:"required"`
|
|
PassportGivenAt FlexibleTime `json:"passportGivenAt" swaggertype:"string" format:"date"`
|
|
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
|
BornPlace string `json:"bornPlace" binding:"required"`
|
|
JobLocation *string `json:"jobLocation"`
|
|
PassportAddress *string `json:"passportAddress"`
|
|
RealAddress *string `json:"realAddress"`
|
|
Phone *string `json:"phone"`
|
|
PhoneAdditional *string `json:"phoneAdditional"`
|
|
Status *string `json:"status"`
|
|
PassportOne string `json:"passportOne" binding:"required"`
|
|
PassportTwo string `json:"passportTwo" binding:"required"`
|
|
PassportThree string `json:"passportThree" binding:"required"`
|
|
PassportFour string `json:"passportFour" binding:"required"`
|
|
Notes *string `json:"notes"`
|
|
UserId *FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
|
Paid *bool `json:"paid"`
|
|
}
|
|
|
|
type UpdateCardOrderDTO struct {
|
|
UniqueId *string `json:"uniqueId"`
|
|
CardStateId FlexibleInt64 `json:"cardStateId" binding:"required" swaggertype:"integer"`
|
|
CardTypeId FlexibleInt64 `json:"cardTypeId" binding:"required" swaggertype:"integer"`
|
|
Region string `json:"region" binding:"required"`
|
|
BranchId FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
|
CustomerName string `json:"customerName" binding:"required"`
|
|
CustomerSurname string `json:"customerSurname" binding:"required"`
|
|
CustomerPatronicName *string `json:"customerPatronicName"`
|
|
BornAt *FlexibleTime `json:"bornAt" swaggertype:"string" format:"date"`
|
|
OldSurname *string `json:"oldSurname"`
|
|
Citizenship string `json:"citizenship" binding:"required"`
|
|
PassportSerie string `json:"passportSerie" binding:"required"`
|
|
PassportId string `json:"passportId" binding:"required"`
|
|
PassportGivenAt FlexibleTime `json:"passportGivenAt" swaggertype:"string" format:"date"`
|
|
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
|
BornPlace string `json:"bornPlace" binding:"required"`
|
|
JobLocation *string `json:"jobLocation"`
|
|
PassportAddress *string `json:"passportAddress"`
|
|
RealAddress *string `json:"realAddress"`
|
|
Phone *string `json:"phone"`
|
|
PhoneAdditional *string `json:"phoneAdditional"`
|
|
Status *string `json:"status"`
|
|
PassportOne string `json:"passportOne" binding:"required"`
|
|
PassportTwo string `json:"passportTwo" binding:"required"`
|
|
PassportThree string `json:"passportThree" binding:"required"`
|
|
PassportFour string `json:"passportFour" binding:"required"`
|
|
Notes *string `json:"notes"`
|
|
UserId *FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
|
Paid bool `json:"paid"`
|
|
}
|
|
|
|
type ListFilter struct {
|
|
Status *string
|
|
BranchId *int64
|
|
UserId *int64
|
|
CardStateId *int64
|
|
CardTypeId *int64
|
|
Region string
|
|
Page int
|
|
Limit int
|
|
}
|
|
|
|
type ListCardOrderDTO struct {
|
|
Count int64 `json:"count"`
|
|
CardOrders []CardOrderDTO `json:"cardOrders"`
|
|
}
|