models

package
v0.0.0-...-75cb93a Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: BSD-2-Clause Imports: 6 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 passwordhash and password from user input

func DeleteCarpark

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

func GetAllUsers

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

GetAllUsers returns a list of all users in the database

func GetCarParks

func GetCarParks(db *gorm.DB) (*[]Carpark, error)

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes password from user input

Types

type Carpark

type Carpark struct {
	gorm.Model

	//ParkID		string	`gorm:"size:100,not null;unique"	json:"park_id"`
	Name        string `gorm:"size:100,not null"			json:"name"`
	Description string `gorm:"not null" 					json:"description"`
	Location    string `gorm:"size:100,not null" 			json:"location"`
	Capacity    string `gorm:"size:100,not null" 			json:"capacity"`
	City        string `gorm:"size:100,not null" 			json:"city"`
	CreatedBy   User   `gorm:"foreignKey:UserID;"			json:"-"`
	UserID      uint   `gorm:"not null" 					json:"user_id"`
}

Carpark is the car parks

func GetCarParkById

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

func (*Carpark) GetCarPark

func (cp *Carpark) GetCarPark(db *gorm.DB) (*Carpark, error)

func (*Carpark) Prepare

func (cp *Carpark) Prepare()

func (*Carpark) Save

func (cp *Carpark) Save(db *gorm.DB) (*Carpark, error)

func (*Carpark) UpdateCarpark

func (cp *Carpark) UpdateCarpark(id int, db *gorm.DB) (*Carpark, error)

func (*Carpark) Validate

func (cp *Carpark) Validate() error

type User

type User struct {
	gorm.Model

	ProfilePicture string `gorm:"size:255;not null"					json:"profilepicture"`
	Email          string `gorm:"type:varchar(100)e;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 is the car owner

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 the user by email

func (*User) Prepare

func (u *User) Prepare()

Prepare strips user input of whitespaces

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

type WebApp

type WebApp struct {
	Router *mux.Router
	DB     *gorm.DB
}

Jump to

Keyboard shortcuts

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