db

package
v0.0.0-...-47b6295 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	CreateUser(user *models.User) (*models.User, error)
	FindUserByUsername(username string) (*models.User, error)
	FindUserByEmail(email string) (*models.User, error)
	UpdateUser(user *models.User) error
	AddToBlackList(blacklist *models.Blacklist) error
	TokenInBlacklist(token *string) bool
	FindUserByPhone(phone string) (*models.User, error)
	FindAllUsersExcept(except string) ([]models.User, error)
}

DB provides access to the different db

type MongoDB

type MongoDB struct {
	DB *mgo.Database
}

MongoDB implements the DB interface

func (*MongoDB) AddToBlackList

func (mdb *MongoDB) AddToBlackList(blacklist *models.Blacklist) error

AddToBlackList puts blacklist into the blacklist collection

func (*MongoDB) CreateUser

func (mdb *MongoDB) CreateUser(user *models.User) (*models.User, error)

CreateUser creates a new user in the DB

func (*MongoDB) FindAllUsersExcept

func (mdb *MongoDB) FindAllUsersExcept(except string) ([]models.User, error)

FindAllUsersExcept returns all the users expcept the one specified in the except parameter

func (*MongoDB) FindUserByEmail

func (mdb *MongoDB) FindUserByEmail(email string) (*models.User, error)

FindUserByEmail finds a user by email

func (MongoDB) FindUserByPhone

func (mdb MongoDB) FindUserByPhone(phone string) (*models.User, error)

FindUserByPhone finds a user by the phone

func (*MongoDB) FindUserByUsername

func (mdb *MongoDB) FindUserByUsername(username string) (*models.User, error)

FindUserByUsername finds a user by the username

func (*MongoDB) Init

func (mdb *MongoDB) Init()

Init sets up the mongodb instance

func (*MongoDB) TokenInBlacklist

func (mdb *MongoDB) TokenInBlacklist(token *string) bool

TokenInBlacklist checks if token is already in the blacklist collection

func (*MongoDB) UpdateUser

func (mdb *MongoDB) UpdateUser(user *models.User) error

UpdateUser updates user in the collection

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError defines error that occur due to validation

func (ValidationError) Error

func (v ValidationError) Error() string

Jump to

Keyboard shortcuts

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