generated from VLADIMIR/template
add game statuses
This commit is contained in:
@@ -177,3 +177,83 @@ func (r *GamesRepo) UpdateGame(
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) StartGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
`UPDATE games
|
||||
SET
|
||||
status = 'run',
|
||||
start_at = NOW(),
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrGameNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) PauseGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
`UPDATE games
|
||||
SET
|
||||
status = 'pause',
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrGameNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) FinishGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
`UPDATE games
|
||||
SET
|
||||
status = 'finish',
|
||||
ended_at = NOW(),
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrGameNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) ResetGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
`UPDATE games
|
||||
SET
|
||||
status = 'draft',
|
||||
started_at = DEFAULT,
|
||||
ended_at = DEFAULT,
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrGameNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user