models

package
v0.0.0-...-3483558 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllRoutes

type AllRoutes struct {
	Source string      `json:"source"`
	Routes []RouteInfo `json:"routes"`
}

Represents all possible Routes starting from source

func (*AllRoutes) GetViewModel

func (r *AllRoutes) GetViewModel() interface{}

Returns the View Model of AllRoutes

func (*AllRoutes) SortByDistance

func (r *AllRoutes) SortByDistance()

Sorts the RoutesInfo array by Distance

func (*AllRoutes) SortByDuration

func (r *AllRoutes) SortByDuration()

Sorts the RoutesInfo array by duration

type Model

type Model interface {
	GetViewModel() interface{}
}

GetViewModel will be called before the model is sent for modifying the content of the model

type NewUser

type NewUser struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Role     string `json:"role"`
}

NewUser represents the user sent by the client as http request body TODO should be renamed

type RouteInfo

type RouteInfo struct {
	Destination string  `json:"destination"`
	Duration    float64 `json:"duration"`
	Distance    float64 `json:"distance"`
}

Represents the Information about the Route

type User

type User struct {
	gorm.Model
	Username string `gorm:"column:username;unique;not null"`
	Role     string `gorm:"column:role,default:USER"`
	Password string `gorm:"column:password;not null"`
}

User represents the model of the users table also includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt. Note Table name is users

func (*User) BeforeSave

func (u *User) BeforeSave() (err error)

BeforeSave Hash the password before saving to the database

func (*User) BeforeUpdate

func (u *User) BeforeUpdate() (err error)

BeforeSave Hash the password before update to the database NOTE this function will be called by the GORM before update

func (*User) CheckPasswordHash

func (u *User) CheckPasswordHash(password string) bool

CheckPasswordHash checks whether the given password is correct or not Returns true if password matchs else false

func (*User) GenerateJWT

func (u *User) GenerateJWT() (string, error)

GenerateJWT generates JWT token to be used for auth

func (*User) GetViewModel

func (u *User) GetViewModel() interface{}

GetViewModel get Executed before the object get sent to the client Returns The User's View Model

Jump to

Keyboard shortcuts

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