generated from VLADIMIR/template
fix
This commit is contained in:
@@ -2,6 +2,7 @@ package repos
|
||||
|
||||
import "time"
|
||||
|
||||
// Scenario describes a stored scenario.
|
||||
type Scenario struct {
|
||||
ID int
|
||||
Name string
|
||||
|
||||
@@ -11,19 +11,23 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrScenarioNotFound indicates that a scenario was not found.
|
||||
ErrScenarioNotFound = errors.New("Сценарий не найден")
|
||||
)
|
||||
|
||||
// ScenariosRepo persists scenarios.
|
||||
type ScenariosRepo struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
// NewScenariosRepo creates a scenarios repository.
|
||||
func NewScenariosRepo(pool *pgxpool.Pool) *ScenariosRepo {
|
||||
return &ScenariosRepo{
|
||||
pool: pool,
|
||||
}
|
||||
}
|
||||
|
||||
// AddScenario stores a scenario.
|
||||
func (r *ScenariosRepo) AddScenario(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
@@ -45,6 +49,7 @@ func (r *ScenariosRepo) AddScenario(
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetScenariosByAuthorID returns scenarios created by an author.
|
||||
func (r *ScenariosRepo) GetScenariosByAuthorID(
|
||||
ctx context.Context,
|
||||
authorID int,
|
||||
@@ -107,6 +112,7 @@ func (r *ScenariosRepo) GetScenariosByAuthorID(
|
||||
return scenarios, nil
|
||||
}
|
||||
|
||||
// GetScenariosByStatus returns scenarios with the requested status.
|
||||
func (r *ScenariosRepo) GetScenariosByStatus(
|
||||
ctx context.Context,
|
||||
status string,
|
||||
@@ -169,6 +175,7 @@ func (r *ScenariosRepo) GetScenariosByStatus(
|
||||
return scenarios, nil
|
||||
}
|
||||
|
||||
// GetScenarioByID returns a scenario by ID.
|
||||
func (r *ScenariosRepo) GetScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
@@ -313,6 +320,7 @@ func (r *ScenariosRepo) DeleteScenarioByID(
|
||||
return tag.RowsAffected() > 0, nil
|
||||
}
|
||||
|
||||
// GetStoryByScenarioID returns the story JSON for a scenario.
|
||||
func (r *ScenariosRepo) GetStoryByScenarioID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
|
||||
@@ -109,8 +109,6 @@ func (r *TeamsRepo) AnswerParticipation(ctx context.Context, token, answer strin
|
||||
return p, ErrParticipationClosed
|
||||
}
|
||||
|
||||
// Пятиминутная аренда переживает перезапуски и не позволяет рабочим процессам
|
||||
// отправить одну задачу повторно.
|
||||
// ClaimParticipationEmail claims the next participation email job.
|
||||
func (r *TeamsRepo) ClaimParticipationEmail(ctx context.Context) (*Participation, error) {
|
||||
p := &Participation{}
|
||||
|
||||
@@ -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