repository

package
v0.0.0-...-45bb23c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresDB

func NewPostgresDB(cfg *configs.DBConfig) (*sqlx.DB, error)

NewPostgresDB gives access for PostgreSQL.

Types

type AuthorizationRepository

type AuthorizationRepository interface {
	CreateUser(ctx context.Context, user models.User) (int, error)
	GetUser(ctx context.Context, email string) (models.User, error)
}

AuthorizationRepository interface contains database methods of the user.

type ImagesRepository

type ImagesRepository interface {
	InsertImage(ctx context.Context, filename, format string) (string, error)
	RequestsHistory(ctx context.Context, sourceFormat, targetFormat, imageID, filename string, userID, ratio int) (string, error)
	GetRequestFromID(ctx context.Context, userID int) ([]models.Request, error)
	UpdateRequest(ctx context.Context, status, imageID, targetID string) error
	GetImageByID(ctx context.Context, id string) (models.Images, error)
}

ImagesRepository interface contains database methods of images.

type RepoInterface

type RepoInterface interface {
	AuthorizationRepository
	ImagesRepository
	Transactional(f func(repo RepoInterface) error) error
}

RepoInterface contains AuthorizationRepository, ImagesRepository and Transactional func.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository struct provides access to the database.

func New

func New(db *sqlx.DB) *Repository

New is constructor of the Repository.

func (*Repository) CreateUser

func (r *Repository) CreateUser(ctx context.Context, user models.User) (int, error)

CreateUser method is for inserting data into users table.

func (*Repository) GetImageByID

func (r *Repository) GetImageByID(ctx context.Context, id string) (models.Images, error)

GetImageByID gets id of the image.

func (*Repository) GetRequestFromID

func (r *Repository) GetRequestFromID(ctx context.Context, userID int) ([]models.Request, error)

GetRequestFromID allows to get the history of users requests.

func (*Repository) GetUser

func (r *Repository) GetUser(ctx context.Context, email string) (models.User, error)

GetUser gets the user id and password.

func (*Repository) InsertImage

func (r *Repository) InsertImage(ctx context.Context, filename, format string) (string, error)

InsertImage inserts image to the database and returns image id.

func (*Repository) RequestsHistory

func (r *Repository) RequestsHistory(ctx context.Context, sourceFormat, targetFormat, imageID, filename string, userID, ratio int) (string, error)

RequestsHistory add data to request table and returns request id.

func (*Repository) Transactional

func (r *Repository) Transactional(f func(repo RepoInterface) error) error

Transactional func implement atomicity,it begins transactions,rollback and commit them.

func (*Repository) UpdateRequest

func (r *Repository) UpdateRequest(ctx context.Context, status, imageID, targetID string) error

UpdateRequest updates request status.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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