models

package
v0.0.0-...-05b3b51 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 4 Imported by: 0

README

Models package

//TODO: write modules doc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	gorm.Model
}

BaseModel is base class for all models, created for flexibility later,

  • currently same as gorm.Model

type DateT

type DateT time.Time

DateT for date references in database

type DeleterSaver

type DeleterSaver interface {
	Delete(bool)
	Save()
}

DeleterSaver interface to define methods for base models with ID

type TimestampT

type TimestampT time.Time

TimestampT for timestamp references in database

type User

type User struct {
	BaseModel

	GoogleID        string `gorm:"unique_index;default:null;"`
	FacebookID      string `gorm:"unique_index;default:null;"`
	Password        string `gorm:"default:null;"`
	FirstName       string `gorm:"not null"`
	LastName        string `gorm:"not null"`
	Email           string `gorm:"type:varchar(100);unique_index;not null;"`
	EmailVerifiedAt time.Time
	Role            uint `gorm:"default:1;"`
}

User is a base model of user

func CheckCredentials

func CheckCredentials(email, password string) *User

CheckCredentials returns user if email-password combination exists, otherwise null

func GetUserByEmail

func GetUserByEmail(email string) *User

GetUserByEmail returns user with given email if exists, otherwise null

func GetUserByID

func GetUserByID(ID uint) *User

GetUserByID returns user with given ID or null

func (*User) Delete

func (u *User) Delete(softDelete bool)

Delete deletes user, softDelete parameter specifies whether value should be deleted permanently

*Primary key (ID) must be set

func (*User) Save

func (u *User) Save()

Save updates model in the database, if primary key isn't set creates model

func (*User) SaveUserIfDoesntExist

func (u *User) SaveUserIfDoesntExist()

SaveUserIfDoesntExist saves user to database if emails isn't occupied

func (*User) ToMap

func (u *User) ToMap() *map[string]interface{}

Return map to be parsed in json response

Jump to

Keyboard shortcuts

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