generated from VLADIMIR/template
add game
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"evening_detective_server/internal/repos"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -22,6 +23,37 @@ func NewTeamsRepo(pool *pgxpool.Pool) *TeamsRepo {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TeamsRepo) GetTeamByID(ctx context.Context, id int) (*repos.Team, error) {
|
||||
team := &repos.Team{}
|
||||
row := r.pool.QueryRow(
|
||||
ctx,
|
||||
`SELECT
|
||||
id,
|
||||
name,
|
||||
status,
|
||||
password,
|
||||
scenario_id
|
||||
FROM teams
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
err := row.Scan(
|
||||
&team.ID,
|
||||
&team.Name,
|
||||
&team.Status,
|
||||
&team.Password,
|
||||
&team.ScenarioId,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrTeamNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return team, nil
|
||||
}
|
||||
|
||||
func (r *TeamsRepo) GetTeamsByGameID(
|
||||
ctx context.Context,
|
||||
gameId int,
|
||||
|
||||
Reference in New Issue
Block a user