switched to gorm..
This commit is contained in:
@@ -1,23 +1,39 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"GoMembership/internal/constants"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DateOfBirth time.Time `json:"date_of_birth"`
|
||||
Email string `json:"email"`
|
||||
ProfilePicture string `json:"profile_picture"`
|
||||
FirstName string `json:"first_name"`
|
||||
Salt string `json:"-"`
|
||||
LastName string `json:"last_name"`
|
||||
Phone string `json:"phone"`
|
||||
Status string `json:"status"`
|
||||
Notes string `json:"notes"`
|
||||
PaymentStatus string `json:"payment_status"`
|
||||
Password string `json:"password"`
|
||||
Address string `json:"address"`
|
||||
ID int64 `json:"id"`
|
||||
RoleID int8 `json:"role_id"`
|
||||
DriversIDChecked bool `json:"drivers_id_checked"`
|
||||
UpdatedAt time.Time
|
||||
DateOfBirth time.Time `gorm:"not null" json:"date_of_birth"`
|
||||
CreatedAt time.Time
|
||||
Salt *string `json:"-"`
|
||||
Phone *string `json:"phone"`
|
||||
Notes *string `json:"notes"`
|
||||
FirstName string `gorm:"not null" json:"first_name"`
|
||||
Password string `json:"password"`
|
||||
Email string `gorm:"unique;not null" json:"email"`
|
||||
LastName string `gorm:"not null" json:"last_name"`
|
||||
ProfilePicture string `json:"profile_picture"`
|
||||
Address string `gorm:"not null" json:"address"`
|
||||
Consents []Consent `gorm:"constraint:OnUpdate:CASCADE"`
|
||||
BankAccount BankAccount `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
Verification Verification `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
Membership Membership `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
ID int64 `gorm:"primaryKey"`
|
||||
PaymentStatus int8 `json:"payment_status"`
|
||||
Status int8 `json:"status"`
|
||||
RoleID int8 `json:"role_id"`
|
||||
}
|
||||
|
||||
// BeforeCreate sets the default value for Status
|
||||
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
if u.Status == 0 { // Assuming 0 is an unset value
|
||||
u.Status = constants.UnverifiedStatus
|
||||
u.PaymentStatus = constants.AwaitingPaymentStatus
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user