feat: initial commit
This commit is contained in:
24
models/organization.go
Normal file
24
models/organization.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Organization struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()" json:"id"`
|
||||
Name string `gorm:"unique;not null" json:"name"`
|
||||
DisplayName string `gorm:"not null" json:"display_name"`
|
||||
CreatedBy uuid.UUID `gorm:"type:uuid;" json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
Creator User `gorm:"foreignKey:CreatedBy" json:"creator,omitempty"`
|
||||
}
|
||||
|
||||
func (Organization) TableName() string {
|
||||
return "organizations"
|
||||
}
|
||||
26
models/quiz.go
Normal file
26
models/quiz.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Quiz struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()" json:"id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
Config interface{} `gorm:"type:jsonb" json:"config"`
|
||||
CreatedBy uuid.UUID `gorm:"type:uuid;not null" json:"created_by"`
|
||||
UpdatedBy uuid.UUID `gorm:"type:uuid" json:"updated_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
Creator User `gorm:"foreignKey:CreatedBy;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"creator,omitempty"`
|
||||
Updater User `gorm:"foreignKey:UpdatedBy;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"updater,omitempty"`
|
||||
}
|
||||
|
||||
func (Quiz) TableName() string {
|
||||
return "quizzes"
|
||||
}
|
||||
31
models/user.go
Normal file
31
models/user.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()" json:"id"`
|
||||
FirstName string `gorm:"not null" json:"first_name"`
|
||||
LastName string `gorm:"not null" json:"last_name"`
|
||||
Username string `gorm:"unique;not null" json:"username"`
|
||||
Email string `gorm:"unique;not null" json:"email"`
|
||||
Password string `gorm:"unique;not null" json:"-"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
Organizations []Organization `gorm:"many2many:user_organizations;" json:"organizations,omitempty"`
|
||||
|
||||
CreatedOrganization []Organization `gorm:"foreignKey:CreatedBy" json:"created_organization,omitempty"`
|
||||
|
||||
CreatedQuiz []Quiz `gorm:"foreignKey:CreatedBy" json:"created_quiz,omitempty"`
|
||||
UpdatedQuiz []Quiz `gorm:"foreignKey:UpdatedBy" json:"updated_quiz,omitempty"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
Reference in New Issue
Block a user