models

package
v0.0.0-...-27abfae Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConnection

func GetConnection() *sqlx.DB

GetConnection Returns database connection without a database

func GetDatabase

func GetDatabase() *sqlx.DB

GetDatabase Returns database connection from pool

func GetSQLConnection

func GetSQLConnection() *sql.DB

GetSQLConnection Returns database connection without a database with the default sql package

func GetSQLDatabase

func GetSQLDatabase() *sql.DB

GetSQLDatabase Returns database connection from pool with the default sql package

Types

type JwtClaims

type JwtClaims struct {
	User           *User  `json:"user"`
	RefreshTokenID uint64 `json:"refresh_token_id"`
	jwt.StandardClaims
}

JwtClaims json web token claim

type JwtRefreshTokenClaims

type JwtRefreshTokenClaims struct {
	UserID   uint64 `json:"user_id" db:"user_id"`
	DeviceID string `json:"device_id" db:"device_id"`
	jwt.StandardClaims
}

JwtRefreshTokenClaims json web token claim for refresh token

type Log

type Log struct {
	ID       uint64         `json:"id" db:"id"`
	UserID   uint64         `json:"user_id" db:"user_id"`
	Language enums.Language `json:"language" db:"language"`
	Date     string         `json:"date" db:"date"`
	Duration uint64         `json:"duration" db:"duration"`
	Activity enums.Activity `json:"activity" db:"activity"`
	Notes    types.JSONText `json:"notes" db:"notes"`
}

Log model

func (*Log) IsOwner

func (log *Log) IsOwner(userID uint64) bool

IsOwner checks the owner

func (*Log) Validate

func (log *Log) Validate() error

Validate the Log model

type LogCollection

type LogCollection struct {
	Logs []Log `json:"logs"`
}

LogCollection array of logs

func (*LogCollection) Add

func (logCollection *LogCollection) Add(log *Log) (uint64, error)

Add a log to the database

func (*LogCollection) ByLanguage

func (logCollection *LogCollection) ByLanguage(language enums.Language)

ByLanguage only keeps the logs for a certain language

func (*LogCollection) Delete

func (logCollection *LogCollection) Delete(log *Log) error

Delete a log

func (*LogCollection) Get

func (logCollection *LogCollection) Get(id uint64) (*Log, error)

Get a log by id

func (*LogCollection) GetAll

func (logCollection *LogCollection) GetAll() error

GetAll returns all logs

func (*LogCollection) GetAllFromUser

func (logCollection *LogCollection) GetAllFromUser(userID uint64) error

GetAllFromUser returns all logs from a certain user

func (*LogCollection) GetAllWithFilters

func (logCollection *LogCollection) GetAllWithFilters(filters map[string]interface{}) error

GetAllWithFilters returns all logs with filters applied

func (*LogCollection) Length

func (logCollection *LogCollection) Length() int

Length returns the amount of logs in the collection

func (*LogCollection) Update

func (logCollection *LogCollection) Update(log *Log) error

Update a log

type Preferences

type Preferences struct {
	Languages     []enums.Language `json:"languages" db:"languages"`
	PublicProfile bool             `json:"public_profile" db:"public_profile"`
}

Preferences model

func (*Preferences) Scan

func (preferences *Preferences) Scan(src interface{}) error

Scan of preferences (support for embedded preferences)

func (Preferences) Value

func (preferences Preferences) Value() (driver.Value, error)

Value of preferences (support for embedded preferences)

type RefreshToken

type RefreshToken struct {
	ID            uint64      `json:"id" db:"id"`
	UserID        uint64      `json:"user_id" db:"user_id"`
	DeviceID      string      `json:"device_id" db:"device_id"`
	RefreshToken  string      `json:"refresh_token" db:"refresh_token"`
	CreatedAt     time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt     time.Time   `json:"updated_at" db:"updated_at"`
	InvalidatedAt pq.NullTime `json:"invalidated_at" db:"invalidated_at"`
}

RefreshToken model

func (*RefreshToken) GenerateRefreshToken

func (refreshToken *RefreshToken) GenerateRefreshToken() error

func (*RefreshToken) GenerateRefreshTokenString

func (refreshToken *RefreshToken) GenerateRefreshTokenString() (string, error)

GenerateRefreshToken generates a new refresh token that's valid for one year for a given user and device and returns the signed JWT token

func (*RefreshToken) Validate

func (refreshToken *RefreshToken) Validate() error

Validate the RefreshToken model

type RefreshTokenCollection

type RefreshTokenCollection struct {
	RefreshTokens []RefreshToken `json:"refresh_tokens"`
}

RefreshTokenCollection array of refresh tokens

func (*RefreshTokenCollection) Add

func (refreshTokenCollection *RefreshTokenCollection) Add(refreshToken *RefreshToken) (uint64, error)

Add a refresh token to the database

func (*RefreshTokenCollection) Get

func (refreshTokenCollection *RefreshTokenCollection) Get(id uint64) (*RefreshToken, error)

Get a refresh token by id

func (*RefreshTokenCollection) GetByClaims

func (refreshTokenCollection *RefreshTokenCollection) GetByClaims(claims *JwtRefreshTokenClaims) (*RefreshToken, error)

Get a refresh token by claims nil is returned when a token is invalidated

func (*RefreshTokenCollection) Length

func (refreshTokenCollection *RefreshTokenCollection) Length() int

Length returns the amount of refresh tokens in the collection

type User

type User struct {
	ID          uint64      `json:"id" db:"id"`
	Email       string      `json:"email" db:"email"`
	DisplayName string      `json:"display_name" db:"display_name"`
	Password    string      `json:"password" db:"password"`
	Role        enums.Role  `json:"role" db:"role"`
	Preferences Preferences `json:"preferences" db:"preferences"`
}

User model

func (*User) HashPassword

func (user *User) HashPassword() error

HashPassword hash the currently set password

func (*User) Validate

func (user *User) Validate() error

Validate the User model

type UserCollection

type UserCollection struct {
	Users []User `json:"users"`
}

UserCollection array of users

func (*UserCollection) Add

func (userCollection *UserCollection) Add(user *User) (uint64, error)

Add a user to the database

func (*UserCollection) Get

func (userCollection *UserCollection) Get(id uint64) (*User, error)

Get a user by id

func (*UserCollection) GetAll

func (userCollection *UserCollection) GetAll() error

GetAll returns all users

func (*UserCollection) GetAuthenticationData

func (userCollection *UserCollection) GetAuthenticationData(email string) (*User, error)

GetAuthenticationData get data needed to generate jwt token

func (*UserCollection) Length

func (userCollection *UserCollection) Length() int

Length returns the amount of users in the collection

func (*UserCollection) Update

func (userCollection *UserCollection) Update(user *User) error

Update a user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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