models

package
v0.0.0-...-f80fa47 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) error

CheckPasswordHash checks password hash and password from user input if they match

func DeleteTask

func DeleteTask(id int, db *gorm.DB) error

func GetAllUsers

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

GetAllUsers returns a list of all the user

func GetTasks

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

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes password from user input

Types

type Task

type Task struct {
	gorm.Model
	Name      string `gorm:"size:100;not null"        json:"name"`
	Completed bool   `gorm:"not null"                 json:"completed"`
}

Task structure with id, name, and completion status

func GetTaskById

func GetTaskById(id int, db *gorm.DB) (*Task, error)

func (*Task) Prepare

func (t *Task) Prepare()

func (*Task) Save

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

func (*Task) UpdateTask

func (t *Task) UpdateTask(id int, db *gorm.DB) (*Task, error)

TODO: change to toggle task completion status

func (*Task) Validate

func (t *Task) Validate() error

type User

type User struct {
	gorm.Model
	Email     string `gorm:"type:varchar(100);unique_index" json:"email"`
	FirstName string `gorm:"size:100;not null"              json:"firstname"`
	LastName  string `gorm:"size:100;not null"              json:"lastname"`
	Password  string `gorm:"size:100;not null"              json:"password"`
}

User model

func (*User) BeforeSave

func (u *User) BeforeSave() error

BeforeSave hashes user password

func (*User) GetUser

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

GetUser returns a user based on email

func (*User) Prepare

func (u *User) Prepare()

Prepare strips user input of any white spaces

func (*User) SaveUser

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

SaveUser adds a user to the database

func (*User) Validate

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

Validate user input

Jump to

Keyboard shortcuts

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