made Licence optional
This commit is contained in:
@@ -7,11 +7,11 @@ import (
|
||||
type Licence struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
Status int8 `json:"status" binding:"omitempty,number"`
|
||||
Number string `json:"number" binding:"omitempty,euDriversLicence,safe_content"`
|
||||
IssuedDate time.Time `json:"issued_date" binding:"omitempty,lte"`
|
||||
ExpirationDate time.Time `json:"expiration_date" binding:"omitempty,gt"`
|
||||
Number string `json:"number" binding:"omitempty,safe_content"`
|
||||
IssuedDate time.Time `json:"issued_date" binding:"omitempty"`
|
||||
ExpirationDate time.Time `json:"expiration_date" binding:"omitempty"`
|
||||
IssuingCountry string `json:"country" binding:"safe_content"`
|
||||
Categories []Category `json:"licence_categories" gorm:"many2many:licence_2_categories"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:licence_2_categories"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
|
||||
@@ -29,7 +29,7 @@ type User struct {
|
||||
VerificationID uint
|
||||
Membership Membership `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"membership"`
|
||||
MembershipID uint
|
||||
Licence Licence `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"licence"`
|
||||
Licence *Licence `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"licence"`
|
||||
LicenceID uint
|
||||
ID uint `json:"id"`
|
||||
PaymentStatus int8 `json:"payment_status"`
|
||||
@@ -60,7 +60,7 @@ func (u *User) PasswordMatches(plaintextPassword string) (bool, error) {
|
||||
}
|
||||
|
||||
func (u *User) Safe() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
result := map[string]interface{}{
|
||||
"email": u.Email,
|
||||
"first_name": u.FirstName,
|
||||
"last_name": u.LastName,
|
||||
@@ -90,6 +90,9 @@ func (u *User) Safe() map[string]interface{} {
|
||||
"included_per_month": u.Membership.SubscriptionModel.IncludedPerMonth,
|
||||
},
|
||||
},
|
||||
"licence": map[string]interface{}{
|
||||
"id": 0,
|
||||
},
|
||||
"bank_account": map[string]interface{}{
|
||||
"id": u.BankAccount.ID,
|
||||
"mandate_date_signed": u.BankAccount.MandateDateSigned,
|
||||
@@ -99,7 +102,10 @@ func (u *User) Safe() map[string]interface{} {
|
||||
"bic": u.BankAccount.BIC,
|
||||
"mandate_reference": u.BankAccount.MandateReference,
|
||||
},
|
||||
"licence": map[string]interface{}{
|
||||
}
|
||||
|
||||
if u.Licence != nil {
|
||||
result["licence"] = map[string]interface{}{
|
||||
"id": u.Licence.ID,
|
||||
"number": u.Licence.Number,
|
||||
"status": u.Licence.Status,
|
||||
@@ -107,6 +113,8 @@ func (u *User) Safe() map[string]interface{} {
|
||||
"expiration_date": u.Licence.ExpirationDate,
|
||||
"country": u.Licence.IssuingCountry,
|
||||
"licence_categories": u.Licence.Categories,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user