models

package
v0.0.0-...-c91f845 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package models implements the database operations and user management functions

Index

Constants

View Source
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 Hash

func Hash(password string) ([]byte, error)

Hash takes a password and returns the hashed password

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

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

func (t *Task) DeleteATask(db *gorm.DB, tid uint64, uid uint32) (int64, error)

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

func (t *Task) FindAllTasks(db *gorm.DB) (*[]Task, error)

FindAllTasks retrieves all tasks from the database

func (*Task) FindAllTasksByUserID

func (t *Task) FindAllTasksByUserID(db *gorm.DB, uid uint32) (*[]Task, error)

FindAllTasksByUserID is a function to retrieve all tasks associated with a user using the user id

func (*Task) FindTaskByID

func (t *Task) FindTaskByID(db *gorm.DB, tid uint64) (*Task, error)

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) SaveTask

func (t *Task) SaveTask(db *gorm.DB) (*Task, error)

SaveTask saves a task to the database

func (*Task) UpdateATask

func (t *Task) UpdateATask(db *gorm.DB) (*Task, error)

UpdateATask updates a task in the database

func (*Task) Validate

func (t *Task) Validate() error

Validate checks if the task data is valid

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

func (u *User) BeforeSave() error

BeforeSave is a hook that is run before saving the user to the database

func (*User) DeleteAUser

func (u *User) DeleteAUser(db *gorm.DB, uid uint32) (int64, error)

DeleteAUser deletes a user from the database.

func (*User) FindAllUsers

func (u *User) FindAllUsers(db *gorm.DB) (*[]User, error)

FindAllUsers retrieves all users from the database.

func (*User) FindUserByID

func (u *User) FindUserByID(db *gorm.DB, uid uint32) (*User, error)

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) SaveUser

func (u *User) SaveUser(db *gorm.DB) (*User, error)

SaveUser saves a user to the database.

func (*User) UpdateAUser

func (u *User) UpdateAUser(db *gorm.DB, uid uint32) (*User, error)

UpdateAUser updates a user in the database.

func (*User) Validate

func (u *User) Validate(action string) error

Validate validates user fields based on the specified action.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL