models

package
v0.0.0-...-195a7bd Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Actions = map[string]int{
	"reset": 0,
}

Actions holds constants for different token types

Functions

func DeleteNote

func DeleteNote(db *gorm.DB, note *Note) error

DeleteNote deletes a note

func DeleteUser

func DeleteUser(db *gorm.DB, user *User) (err error)

DeleteUser removes a user from the database

func Execute

func Execute(db *gorm.DB, body io.ReadCloser, code, user uuid.UUID) error

Execute runs c.Action against user

func Login

func Login(db *gorm.DB, mail, pass string) (map[string]interface{}, error)

Login authorizes a user and assigns JWT token

func NewCode

func NewCode(db *gorm.DB, action int, userID uuid.UUID) (uuid.UUID, error)

NewCode returns a pointer to a new Code variable

func ToggleNote

func ToggleNote(db *gorm.DB, note *Note) (map[string]interface{}, error)

ToggleNote updates a note

func UpdateNote

func UpdateNote(db *gorm.DB, note *Note) (map[string]interface{}, error)

UpdateNote updates a note

func UpdatePassword

func UpdatePassword(db *gorm.DB, user *User) (err error)

UpdatePassword hashes and updates provided password

func UpdateUser

func UpdateUser(db *gorm.DB, user *User) (map[string]interface{}, error)

UpdateUser updates a user in the db

Types

type Base

type Base struct {
	ID        uuid.UUID  `gorm:"type:uuid;primary_key;"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"update_at"`
	DeletedAt *time.Time `sql:"index" json:"deleted_at"`
}

Base contains common columns for all tables.

func (*Base) BeforeCreate

func (base *Base) BeforeCreate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

type Code

type Code struct {
	Ticket uuid.UUID `json:"ticket"`
	UserID uuid.UUID `json:"userid"`
	Expiry time.Time `json:"expiry"`
	Action int       `json:"action"`
}

Code represents a one time voucher provided to user in certain circumstances

type Note

type Note struct {
	Base
	Subject string    `json:"subject"`
	Content string    `json:"content"`
	Visible bool      `gorm:"default:true" json:"visible"`
	Creator uuid.UUID `gorm:"type:uuid" json:"creator"`
}

Note struct represents a note

func GetNote

func GetNote(db *gorm.DB, id uuid.UUID) (note *Note)

GetNote returns a single note, if present, that matches provided criteria and has visible == true

func GetNotes

func GetNotes(db *gorm.DB) (notes []*Note)

GetNotes returns an array of all notes

func GetNotesFor

func GetNotesFor(db *gorm.DB, user uuid.UUID) (notes []*Note)

GetNotesFor returns an array of notes created by a specific user

func (*Note) Create

func (note *Note) Create(db *gorm.DB) map[string]interface{}

Create adds a new note to the database

func (*Note) Validate

func (note *Note) Validate() (map[string]interface{}, bool)

Validate checks the required parameters sent through the http request body returns message and true if the requirement is met

type Token

type Token struct {
	UserID uuid.UUID
	jwt.StandardClaims
}

Token is a JWT claims struct

type User

type User struct {
	Base
	Name string `json:"name"`
	Mail string `json:"mail"`
	Pass string `json:"pass"`
	Auth string `sql:"-" json:"auth"`
}

User is a struct to rep user

func GetUser

func GetUser(db *gorm.DB, u uuid.UUID) (user *User)

GetUser fetches the user from db

func GetUserByMail

func GetUserByMail(db *gorm.DB, mail string) (user *User)

GetUserByMail fetches the user from db

func (*User) Create

func (user *User) Create(db *gorm.DB) (map[string]interface{}, error)

Create adds the referenced user to the database

func (*User) Validate

func (user *User) Validate(db *gorm.DB) error

Validate checks incoming user details

Jump to

Keyboard shortcuts

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