generated from VLADIMIR/template
fix
This commit is contained in:
@@ -10,11 +10,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrTicketNotFound indicates that a ticket was not found.
|
||||
ErrTicketNotFound = errors.New("Билет не найден")
|
||||
ErrTicketUsed = errors.New("Билет уже использован")
|
||||
ErrGameFinished = errors.New("Игра уже завершена")
|
||||
// ErrTicketUsed indicates that a ticket was already used.
|
||||
ErrTicketUsed = errors.New("Билет уже использован")
|
||||
// ErrGameFinished indicates that the game has finished.
|
||||
ErrGameFinished = errors.New("Игра уже завершена")
|
||||
)
|
||||
|
||||
// Info describes a support ticket.
|
||||
type Info struct {
|
||||
ID int
|
||||
Status string
|
||||
@@ -26,14 +30,17 @@ type Info struct {
|
||||
UsedBy *string
|
||||
}
|
||||
|
||||
// Repo persists support tickets.
|
||||
type Repo struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
// New creates a tickets repository.
|
||||
func New(pool *pgxpool.Pool) *Repo {
|
||||
return &Repo{pool: pool}
|
||||
}
|
||||
|
||||
// CreateBatch creates tickets for a game.
|
||||
func (r *Repo) CreateBatch(ctx context.Context, gameID int, tokenHashes [][]byte) ([]int, error) {
|
||||
tx, err := r.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -58,6 +65,7 @@ func (r *Repo) CreateBatch(ctx context.Context, gameID int, tokenHashes [][]byte
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByHash returns a ticket by token hash.
|
||||
func (r *Repo) GetByHash(ctx context.Context, tokenHash []byte) (*Info, error) {
|
||||
info := &Info{}
|
||||
err := r.pool.QueryRow(ctx, `
|
||||
@@ -74,6 +82,7 @@ func (r *Repo) GetByHash(ctx context.Context, tokenHash []byte) (*Info, error) {
|
||||
return info, err
|
||||
}
|
||||
|
||||
// Accept assigns a ticket to a user.
|
||||
func (r *Repo) Accept(ctx context.Context, tokenHash []byte, userID int) (*Info, error) {
|
||||
var status, gameStatus string
|
||||
if err := r.pool.QueryRow(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user