switched to gorm..

This commit is contained in:
$(pass /github/name)
2024-07-10 14:22:56 +02:00
parent 87e9f71ceb
commit 6ac5491053
27 changed files with 368 additions and 283 deletions

View File

@@ -0,0 +1,13 @@
package models
import "time"
type Verification struct {
UpdatedAt time.Time
CreatedAt time.Time
EmailVerifiedAt *time.Time `gorm:"Default:NULL" json:"email_verified_at"`
IDVerifiedAt *time.Time `gorm:"Default:NULL" json:"id_verified_at"`
VerificationToken string `json:"token"`
ID int64 `gorm:"primaryKey"`
UserID int64 `gorm:"unique;" json:"user_id"`
}

View File

@@ -3,11 +3,14 @@ package models
import "time"
type BankAccount struct {
MandateDateSigned time.Time `json:"mandate_date_signed"`
CreatedAt time.Time
UpdatedAt time.Time
MandateDateSigned time.Time `gorm:"not null" json:"mandate_date_signed"`
Bank string `json:"bank_name"`
AccountHolderName string `json:"account_holder_name"`
IBAN string `json:"iban"`
IBAN string `gorm:"not null" json:"iban"`
BIC string `json:"bic"`
MandateReference string `json:"mandate_reference"`
UserID int `json:"id"`
MandateReference string `gorm:"not null" json:"mandate_reference"`
ID int64 `gorm:"primaryKey"`
UserID int64 `json:"user_id"`
}

View File

@@ -3,11 +3,12 @@ package models
import "time"
type Consent struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
ConsentType string `json:"consent_type"`
UserID int `json:"id"`
CreatedAt time.Time
UpdatedAt time.Time
FirstName string `gorm:"not null" json:"first_name"`
LastName string `gorm:"not null" json:"last_name"`
Email string `gorm:"unique" json:"email"`
ConsentType string `gorm:"not null" json:"consent_type"`
ID int64 `gorm:"primaryKey"`
UserID int64 `gorm:"not null" json:"user_id"`
}

View File

@@ -3,10 +3,14 @@ package models
import "time"
type Membership struct {
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Status string `json:"status"`
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
ParentID int64 `json:"parent_id"`
CreatedAt time.Time
UpdatedAt time.Time
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Status string `json:"status"`
SubscriptionModel SubscriptionModel `gorm:"foreignKey:SubscriptionModelID"`
SubscriptionModelID int64 `json:"subsription_model_id"`
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
ParentID int64 `json:"parent_id"`
}

View File

@@ -1,10 +0,0 @@
package models
type MembershipPlan struct {
Name string `json:"name"`
MonthlyFee float32 `json:"monthly_fee"`
HourlyRate float32 `json:"hourly_rate"`
IncludedPerYear int16 `json:"included_hours_per_year"`
IncludedPerMonth int16 `json:"included_hours_per_month"`
Details string `json:"details"`
}

View File

@@ -0,0 +1,18 @@
package models
import (
"time"
)
type SubscriptionModel struct {
CreatedAt time.Time
UpdatedAt time.Time
Name string `json:"name"`
Details string `json:"details"`
Conditions string `json:"conditions"`
ID int64 `gorm:"primaryKey"`
MonthlyFee float32 `json:"monthly_fee"`
HourlyRate float32 `json:"hourly_rate"`
IncludedPerYear int16 `json:"included_hours_per_year"`
IncludedPerMonth int16 `json:"included_hours_per_month"`
}

View File

@@ -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
}