repositories

package
v0.0.0-...-e1e4618 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkRepository

type LinkRepository struct {
	Storage sto.IStorage
}

LinkRepository implements ILinkRepository

func (*LinkRepository) Create

func (lr *LinkRepository) Create(id, content, ownerID string) (link models.Link, err error)

Create creates a link and save it to the storage This methods will permorn validations over the provided data If the id is left blank, a random one would be assigned The data validations in this method can produce an ErrInvalidID or an ErrInvalidContent

func (*LinkRepository) Delete

func (lr *LinkRepository) Delete(id string) error

Delete deletes a link from the storage If the link does not exists in the storage an NotFoundError would be returned

func (*LinkRepository) DeleteByUser

func (lr *LinkRepository) DeleteByUser(requesterID, id string) error

DeleteByUser deletes a link from the storage If the link does not exists in the storage an NotFoundError would be returned The requester must own the link or be an admin to perform this action

func (*LinkRepository) Get

func (lr *LinkRepository) Get(id string) (models.Link, error)

Get returns the link with specified ID from the storage If the link does not exists in the storage an NotFoundError would be returned

func (*LinkRepository) GetByUser

func (lr *LinkRepository) GetByUser(requesterID, id string) (models.Link, error)

GetByUser returns the link with specified ID from the storage If the link does not exists in the storage an NotFoundError would be returned The requester must own the link or be an admin to perform this action

func (*LinkRepository) GetContentAndIncreaseHitCount

func (lr *LinkRepository) GetContentAndIncreaseHitCount(id string) (string, error)

GetContentAndIncreaseHitCount return the link content and increases the hits number of a link in the storage If the link does not exists in the storage an NotFoundError would be returned

func (*LinkRepository) IncreaseHitCount

func (lr *LinkRepository) IncreaseHitCount(id string) error

IncreaseHitCount increases the hits number of a link in the storage If the link does not exists in the storage an NotFoundError would be returned

func (*LinkRepository) List

func (lr *LinkRepository) List(ownerID string, limit, offset uint) ([]models.Link, error)

List lits the users If the limit is set to 0, no limit will be established, the same applies to the offset if the ownerID is not empty the search would be limited to the owned by the specified user

func (*LinkRepository) ListByUser

func (lr *LinkRepository) ListByUser(requesterID, ownerID string, limit, offset uint) ([]models.Link, error)

ListByUser lits the users If the limit is set to 0, no limit will be established, the same applies to the offset if the ownerID is not empty the search would be limited to the owned owned by the specified user The requester must be the owner of the links or an admin to perform this action

func (*LinkRepository) UpdateContent

func (lr *LinkRepository) UpdateContent(id, content string) error

UpdateContent replaces the content of an existing link If the link doesn't exists in the Link an error would be returned This methods will permorn validations over the provided data The data validations in this method can produce an ErrInvalidContent

func (*LinkRepository) UpdateContentByUser

func (lr *LinkRepository) UpdateContentByUser(requesterID, id, content string) error

UpdateContentByUser replaces the content of an existing link If the link doesn't exists in the Link an error would be returned This methods will permorn validations over the provided data The data validations in this method can produce an ErrInvalidContent The requester must own the link or be an admin to perform this action

type SessionRepository

type SessionRepository struct {
	Storage sto.IStorage
}

func (*SessionRepository) Create

func (sr *SessionRepository) Create(userID string, expireDate int64) (models.Session, error)

func (*SessionRepository) Delete

func (sr *SessionRepository) Delete(id string) error

func (*SessionRepository) DeleteByUser

func (sr *SessionRepository) DeleteByUser(userID, id string) error

func (*SessionRepository) GenerateToken

func (sr *SessionRepository) GenerateToken(sessionID string) (string, error)

func (*SessionRepository) List

func (sr *SessionRepository) List(userID string, limit, offset uint) ([]models.Session, error)

func (*SessionRepository) ValidateAndRenew

func (sr *SessionRepository) ValidateAndRenew(sessionToken string) (string, error)

func (*SessionRepository) ValidateToken

func (sr *SessionRepository) ValidateToken(sessionToken string) (string, error)

type UserRepository

type UserRepository struct {
	Storage sto.IStorage
}

UserRepository implements IUserRepository

func (*UserRepository) CheckLoginCredentials

func (ur *UserRepository) CheckLoginCredentials(name string, password []byte) (bool, error)

CheckLoginCredentials checks if the provided credentials are valid to perform a login

func (*UserRepository) Create

func (ur *UserRepository) Create(name string, password []byte, isAdmin bool) (user models.User, err error)

Create creates an user and save it to the storage This methods will permorn validations over the provided data

func (*UserRepository) CreateByUser

func (ur *UserRepository) CreateByUser(requesterID string, name string, password []byte, isAdmin bool) (user models.User, err error)

CreateByUser creates an user and save it to the storage This methods will permorn validations over the provided data The data validations in this method can produce an ErrInvalidName or an ErrInvalidPassword The requester must be an admin to perform this action

func (*UserRepository) Delete

func (ur *UserRepository) Delete(id string) error

Delete deletes an user from the storage If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned

func (*UserRepository) DeleteByUser

func (ur *UserRepository) DeleteByUser(requesterID, id string) (err error)

DeleteByUser deletes an user from the storage If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned The requester must only delete himself or be an admin to perform this action

func (*UserRepository) Get

func (ur *UserRepository) Get(id string) (models.User, error)

Get returns an user from the storage If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned

func (*UserRepository) GetByUser

func (ur *UserRepository) GetByUser(requesterID, id string) (user models.User, err error)

GetByUser returns an user from the storage If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned The requester must only request information about himself or be an admin to perform this action

func (*UserRepository) List

func (ur *UserRepository) List(limit, offset uint) ([]models.User, error)

List lits the users If the limit is set to 0, no limit will be established, the same applies to the offset

func (*UserRepository) ListByUser

func (ur *UserRepository) ListByUser(requesterID string, limit, offset uint) (users []models.User, err error)

ListByUser lits the users If limit is set to 0, no limit will be established The requester must be an admin to perform this action

func (*UserRepository) Update

func (ur *UserRepository) Update(payload user_repository.UpdatePayload) (err error)

Update replaces the values of the user in the storage with the values of the user provided by parameter If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned This methods will permorn validations over the provided data

func (*UserRepository) UpdateByUser

func (ur *UserRepository) UpdateByUser(requesterID string, user user_repository.UpdatePayload) (err error)

UpdateByUser replaces the values of the user in the storage with the values of the user provided by parameter This methods will permorn validations over the provided data The data validations in this method can produce an ErrInvalidName or an ErrInvalidPassword If the user does not exists in the storage an error pkg/interfaces/storage.NotFoundError would be returned The requestor can only modify information about himself or otherwise be an admin to perform this action. The isAdmin property can only be changed by other admins.

Jump to

Keyboard shortcuts

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