Line data Source code
1 : package request
2 :
3 : // CreateAddressRequest は住所の作成リクエスト。
4 : type CreateAddressRequest struct {
5 : // 目的ID
6 : PurposeID *uint64 `json:"purpose_id" binding:"required,gt=0"`
7 :
8 : // ISO Alpha-2 を想定。厳密チェックはしないなら len=2 だけにして Normalize(大文字化)で吸収。
9 : CountryCode string `json:"country_code" binding:"required,len=2"`
10 :
11 : // JP のとき都道府県を必須にしたい → WhenJP(構造体検証)で担保するのでここは任意 + jpref
12 : AdministrativeArea *string `json:"administrative_area" binding:"omitempty,jp_pref,max=128"`
13 :
14 : // 任意。必要なら max のみ
15 : Locality *string `json:"locality" binding:"omitempty,max=128"`
16 : DependentLocality *string `json:"dependent_locality" binding:"omitempty,max=128"`
17 :
18 : // JP では任意 or 必須かは要件次第。ここでは任意 + 書式は jp_postal に委ねる
19 : PostalCode *string `json:"postal_code" binding:"omitempty,jp_postal"`
20 :
21 : // 必須。前後スペース禁止 + 長さ
22 : AddressLine1 string `json:"address_line1" binding:"required,max=160,no_edge_spaces"`
23 : AddressLine2 *string `json:"address_line2" binding:"omitempty,max=160,no_edge_spaces"`
24 : AddressLine3 *string `json:"address_line3" binding:"omitempty,max=160,no_edge_spaces"`
25 :
26 : // lat/lng は **両方セット or 両方未指定** → CoordPair(構造体検証)で担保
27 : Latitude *float64 `json:"latitude" binding:"omitempty"`
28 : Longitude *float64 `json:"longitude" binding:"omitempty"`
29 : }
30 :
31 : // Normalize はハンドラ層で Bind 後に呼ぶ
32 0 : func (r *CreateAddressRequest) Normalize() {
33 0 : // jpstring を使って正規化(import は省略)
34 0 : // r.CountryCode = strings.ToUpper(strings.TrimSpace(r.CountryCode))
35 0 : // ...必要な項目に jpstring.NormalizeJP / NormalizeDigitsHyphen を適用
36 0 : }
|