feat: CR login, register, subscribe

This commit is contained in:
ericprd
2025-02-24 16:48:20 +08:00
parent ae5b2cb975
commit cb3d06fa02
48 changed files with 1027 additions and 59 deletions
+8 -1
View File
@@ -5,6 +5,8 @@ import (
"os"
staffmodel "github.com/ardeman/project-legalgo-go/database/staff"
subsmodel "github.com/ardeman/project-legalgo-go/database/subscribe"
usermodel "github.com/ardeman/project-legalgo-go/database/user"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
@@ -39,5 +41,10 @@ func NewDB() (*DB, error) {
func (db *DB) Migrate() error {
// Auto Migrate the User model
return db.AutoMigrate(&staffmodel.Staff{})
return db.AutoMigrate(
&staffmodel.Staff{},
&subsmodel.SubscribePlan{},
&subsmodel.Subscribe{},
&usermodel.User{},
)
}
+7 -3
View File
@@ -1,11 +1,15 @@
package staffmodel
import (
"time"
"github.com/google/uuid"
)
type Staff struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
Email string `gorm:"unique,not null" json:"email"`
Password string `gorm:"not null" json:"password"`
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
Email string `gorm:"unique,not null" json:"email"`
Password string `gorm:"not null" json:"password"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}
+27
View File
@@ -0,0 +1,27 @@
package subsmodel
import (
"time"
"github.com/google/uuid"
)
type Subscribe struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
SubscribePlanID uuid.UUID `gorm:"type:uuid;not null" json:"subscribe_plan_id"`
StartDate time.Time `gorm:"default:CURRENT_TIMESTAMP"`
EndDate time.Time `gorm:"default:null"`
Status string `gorm:"default:'inactive'"`
AutoRenew bool `gorm:"default:true"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
SubscribePlan SubscribePlan `gorm:"foreignKey:SubscribePlanID;constraint:OnDelete:CASCADE"`
}
type SubscribePlan struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
Code string `gorm:"not null" json:"code"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}
+19
View File
@@ -0,0 +1,19 @@
package usermodel
import (
"time"
subsmodel "github.com/ardeman/project-legalgo-go/database/subscribe"
"github.com/google/uuid"
)
type User struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
SubscribeID string `gorm:"not null" json:"subscribe_id"`
Email string `gorm:"unique,not null" json:"email"`
Password string `gorm:"not null" json:"password"`
Phone string `gorm:"default:null" json:"phone"`
Subscribe subsmodel.Subscribe `gorm:"foreignKey:SubscribeID;constraint:OnDelete:CASCADE"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}