Users
User model in ClueQuest Go SDK
Schema
Field | Type | Description | Extra Info |
---|---|---|---|
ID | uuid.UUID | Unique identifier for the user. | Primary Key |
FirstName | string | First name of the user. | not null |
LastName | string | Last name of the user. | not null |
Username | string | Username of the user. | unique , not null |
string | Email address of the user. | unique , not null | |
Password | string | Hashed password of the user. | unique , not null |
CreatedAt | time.Time | Timestamp of when the user was created. | Set automatically to current time at creation |
UpdatedAt | time.Time | Timestamp of the last update to the user. | Set automatically to current time at update |
DeletedAt | gorm.DeletedAt | Timestamp of when the user was deleted (if applicable). | It is needed for soft deletion. |
Model
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"`
}
Relationships
CreatedOrganizations
: One-to-many relationship with the Organization model. A user can create multiple organizations.Organizations
: Many-to-many relationship with the Organization model through theuser_organizations
join table. A user can belong to multiple organizations.
Security
The Password
field stores the hashed password of the user and is excluded from JSON serialization for security reasons. Always ensure that passwords are properly hashed before storing them in the database. We use Argon2 for password hashing in ClueQuest SDK.