Documentation
¶
Overview ¶
Package models implements the database operations and user management functions
Index ¶
- Constants
- func Hash(password string) ([]byte, error)
- func VerifyPassword(hashedPassword, password string) error
- type Task
- func (t *Task) DecryptSummary()
- func (t *Task) DeleteATask(db *gorm.DB, tid uint64, uid uint32) (int64, error)
- func (t *Task) EncryptSummary()
- func (t *Task) FindAllTasks(db *gorm.DB) (*[]Task, error)
- func (t *Task) FindAllTasksByUserID(db *gorm.DB, uid uint32) (*[]Task, error)
- func (t *Task) FindTaskByID(db *gorm.DB, tid uint64) (*Task, error)
- func (t *Task) Prepare()
- func (t *Task) SaveTask(db *gorm.DB) (*Task, error)
- func (t *Task) UpdateATask(db *gorm.DB) (*Task, error)
- func (t *Task) Validate() error
- type User
- func (u *User) BeforeSave() error
- func (u *User) DeleteAUser(db *gorm.DB, uid uint32) (int64, error)
- func (u *User) FindAllUsers(db *gorm.DB) (*[]User, error)
- func (u *User) FindUserByID(db *gorm.DB, uid uint32) (*User, error)
- func (u *User) Prepare()
- func (u *User) SaveUser(db *gorm.DB) (*User, error)
- func (u *User) UpdateAUser(db *gorm.DB, uid uint32) (*User, error)
- func (u *User) Validate(action string) error
Constants ¶
const MaxSummarySize = 2500
MaxSummarySize is a constant that represents the maximum size allowed for the summary of a task
Variables ¶
This section is empty.
Functions ¶
func VerifyPassword ¶
VerifyPassword takes a hashed password and password and returns an error if they do not match
Types ¶
type Task ¶
type Task struct { // ID is the unique identifier of the task ID uint64 `gorm:"primary_key;auto_increment" json:"id"` // Summary is a brief description of the task Summary string `gorm:"type:text;not null" json:"summary"` // User is the user who created the task User User `json:"user"` // UserID is the identifier of the user who created the task UserID uint32 `gorm:"not null" json:"user_id"` // CreatedAt is the date and time when the task was created CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` // UpdatedAt is the date and time when the task was last updated UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` }
Task represents a task in the application
func (*Task) DecryptSummary ¶
func (t *Task) DecryptSummary()
DecryptSummary decrypts the summary field of the task
func (*Task) DeleteATask ¶
DeleteATask deletes a task from the database
func (*Task) EncryptSummary ¶
func (t *Task) EncryptSummary()
EncryptSummary encrypts the summary field of the task
func (*Task) FindAllTasks ¶
FindAllTasks retrieves all tasks from the database
func (*Task) FindAllTasksByUserID ¶
FindAllTasksByUserID is a function to retrieve all tasks associated with a user using the user id
func (*Task) FindTaskByID ¶
FindTaskByID is a function to retrieve a single task from the database using the task id
func (*Task) Prepare ¶
func (t *Task) Prepare()
Prepare performs necessary preparation before saving a task to the database
func (*Task) UpdateATask ¶
UpdateATask updates a task in the database
type User ¶
type User struct { ID uint32 `gorm:"primary_key;auto_increment" json:"id"` Name string `gorm:"size:255;not null;unique" json:"name"` Email string `gorm:"size:100;not null;unique" json:"email"` Password string `gorm:"size:100;not null;" json:"password"` Role uint32 `gorm:"not null" json:"role"` CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` }
User represents a user in the database
func (*User) BeforeSave ¶
BeforeSave is a hook that is run before saving the user to the database
func (*User) DeleteAUser ¶
DeleteAUser deletes a user from the database.
func (*User) FindAllUsers ¶
FindAllUsers retrieves all users from the database.
func (*User) FindUserByID ¶
FindUserByID retrieves a user by ID from the database.
func (*User) Prepare ¶
func (u *User) Prepare()
Prepare prepares the user by setting default values and escaping string inputs
func (*User) UpdateAUser ¶
UpdateAUser updates a user in the database.