generated from VLADIMIR/template
fix names
This commit is contained in:
@@ -50,15 +50,15 @@ var (
|
||||
)
|
||||
|
||||
// getTeamAndGame проверяет команду по паролю и возвращает её вместе с игрой.
|
||||
func (s *AnswerService) getTeamAndGame(ctx context.Context, teamId int, password string) (*repos.Team, *repos.Game, error) {
|
||||
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
|
||||
func (s *AnswerService) getTeamAndGame(ctx context.Context, teamID int, password string) (*repos.Team, *repos.Game, error) {
|
||||
team, err := s.teamsRepo.GetTeamByID(ctx, teamID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if team.Password != password || team.ParticipationStatus == "cancelled" {
|
||||
return nil, nil, teams_repo.ErrTeamNotFound
|
||||
}
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, team.GameID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -66,8 +66,8 @@ func (s *AnswerService) getTeamAndGame(ctx context.Context, teamId int, password
|
||||
}
|
||||
|
||||
// getScenarioQuestionsByCode возвращает вопросы сценария игры с индексацией по коду.
|
||||
func (s *AnswerService) getScenarioQuestionsByCode(ctx context.Context, scenarioId int) ([]*storytelling.Question, map[string]*storytelling.Question, error) {
|
||||
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, scenarioId)
|
||||
func (s *AnswerService) getScenarioQuestionsByCode(ctx context.Context, scenarioID int) ([]*storytelling.Question, map[string]*storytelling.Question, error) {
|
||||
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, scenarioID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -81,19 +81,19 @@ func (s *AnswerService) getScenarioQuestionsByCode(ctx context.Context, scenario
|
||||
// GetTeamAnswers возвращает ответы команды на вопросы дела (без баллов:
|
||||
// баллы видны только организаторам). Ответы на удалённые из сценария
|
||||
// вопросы не возвращаются.
|
||||
func (s *AnswerService) GetTeamAnswers(ctx context.Context, teamId int, password string) ([]Answer, error) {
|
||||
_, game, err := s.getTeamAndGame(ctx, teamId, password)
|
||||
func (s *AnswerService) GetTeamAnswers(ctx context.Context, teamID int, password string) ([]Answer, error) {
|
||||
_, game, err := s.getTeamAndGame(ctx, teamID, password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if game.Format == "offline" {
|
||||
return nil, nil
|
||||
}
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teamAnswers, err := s.answersRepo.GetAnswersByTeamID(ctx, teamId)
|
||||
teamAnswers, err := s.answersRepo.GetAnswersByTeamID(ctx, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -114,8 +114,8 @@ func (s *AnswerService) GetTeamAnswers(ctx context.Context, teamId int, password
|
||||
// Доступно только пока игра идёт (статусы run/pause): после завершения
|
||||
// ответы фиксируются для оценки организатором. Переданные коды должны
|
||||
// существовать в сценарии игры; пустая строка очищает ответ.
|
||||
func (s *AnswerService) SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []Answer) error {
|
||||
_, game, err := s.getTeamAndGame(ctx, teamId, password)
|
||||
func (s *AnswerService) SubmitTeamAnswers(ctx context.Context, teamID int, password string, answers []Answer) error {
|
||||
_, game, err := s.getTeamAndGame(ctx, teamID, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (s *AnswerService) SubmitTeamAnswers(ctx context.Context, teamId int, passw
|
||||
}
|
||||
return ErrGameNotStarted
|
||||
}
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func (s *AnswerService) SubmitTeamAnswers(ctx context.Context, teamId int, passw
|
||||
Text: answer.Text,
|
||||
})
|
||||
}
|
||||
return s.answersRepo.UpsertAnswers(ctx, teamId, rows)
|
||||
return s.answersRepo.UpsertAnswers(ctx, teamID, rows)
|
||||
}
|
||||
|
||||
// GetGameAnswers возвращает полную картину для оценки организатором:
|
||||
@@ -154,28 +154,28 @@ func (s *AnswerService) SubmitTeamAnswers(ctx context.Context, teamId int, passw
|
||||
// ответов команды с пустым текстом и без балла (организатор видит его и
|
||||
// может выставить балл, в т.ч. штрафной). Ответы на удалённые из сценария
|
||||
// вопросы не возвращаются (как в GetTeamAnswers).
|
||||
func (s *AnswerService) GetGameAnswers(ctx context.Context, gameId int) (*GameAnswers, error) {
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, gameId)
|
||||
func (s *AnswerService) GetGameAnswers(ctx context.Context, gameID int) (*GameAnswers, error) {
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
questions, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
|
||||
questions, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams, err := s.teamsRepo.GetActiveTeamsByGameID(ctx, gameId)
|
||||
teams, err := s.teamsRepo.GetActiveTeamsByGameID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teamIds := make([]int, 0, len(teams))
|
||||
teamIDs := make([]int, 0, len(teams))
|
||||
for _, team := range teams {
|
||||
teamIds = append(teamIds, team.ID)
|
||||
teamIDs = append(teamIDs, team.ID)
|
||||
}
|
||||
actionsCountByTeamIDs, err := s.actionsRepo.GetActionsCountByTeamIDs(ctx, teamIds)
|
||||
actionsCountByTeamIDs, err := s.actionsRepo.GetActionsCountByTeamIDs(ctx, teamIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.answersRepo.GetAnswersByGameID(ctx, gameId)
|
||||
rows, err := s.answersRepo.GetAnswersByGameID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -185,10 +185,10 @@ func (s *AnswerService) GetGameAnswers(ctx context.Context, gameId int) (*GameAn
|
||||
continue
|
||||
}
|
||||
score := row.Score
|
||||
if answerByTeamAndCode[row.TeamId] == nil {
|
||||
answerByTeamAndCode[row.TeamId] = make(map[string]AnswerScore, len(questions))
|
||||
if answerByTeamAndCode[row.TeamID] == nil {
|
||||
answerByTeamAndCode[row.TeamID] = make(map[string]AnswerScore, len(questions))
|
||||
}
|
||||
answerByTeamAndCode[row.TeamId][row.QuestionCode] = AnswerScore{
|
||||
answerByTeamAndCode[row.TeamID][row.QuestionCode] = AnswerScore{
|
||||
QuestionCode: row.QuestionCode,
|
||||
Text: row.Text,
|
||||
Score: score,
|
||||
@@ -224,23 +224,23 @@ func (s *AnswerService) GetGameAnswers(ctx context.Context, gameId int) (*GameAn
|
||||
// score == nil сбрасывает балл. Балл может быть любым целым числом
|
||||
// (в т.ч. отрицательным — штрафные баллы). Вопрос должен существовать
|
||||
// в сценарии игры.
|
||||
func (s *AnswerService) SetTeamAnswerScore(ctx context.Context, teamId int, questionCode string, score *int) error {
|
||||
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
|
||||
func (s *AnswerService) SetTeamAnswerScore(ctx context.Context, teamID int, questionCode string, score *int) error {
|
||||
team, err := s.teamsRepo.GetTeamByID(ctx, teamID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, team.GameID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
|
||||
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := byCode[questionCode]; !ok {
|
||||
return ErrQuestionNotFound
|
||||
}
|
||||
return s.answersRepo.SetAnswerScore(ctx, teamId, questionCode, score)
|
||||
return s.answersRepo.SetAnswerScore(ctx, teamID, questionCode, score)
|
||||
}
|
||||
|
||||
// GetGameResults возвращает итоговую таблицу игры: вопросы сценария (шапка
|
||||
@@ -248,31 +248,31 @@ func (s *AnswerService) SetTeamAnswerScore(ctx context.Context, teamId int, ques
|
||||
// баллов, с баллами по каждому вопросу (в порядке сценария), числом ходов и
|
||||
// местом. Доступно только после завершения игры (статус finish); неоценённые
|
||||
// вопросы в сумме считаются как 0.
|
||||
func (s *AnswerService) GetGameResults(ctx context.Context, gameId int) (*GameResults, error) {
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, gameId)
|
||||
func (s *AnswerService) GetGameResults(ctx context.Context, gameID int) (*GameResults, error) {
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if game.Status != "finish" {
|
||||
return nil, ErrGameNotFinished
|
||||
}
|
||||
questions, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
|
||||
questions, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams, err := s.teamsRepo.GetActiveTeamsByGameID(ctx, gameId)
|
||||
teams, err := s.teamsRepo.GetActiveTeamsByGameID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teamIds := make([]int, 0, len(teams))
|
||||
teamIDs := make([]int, 0, len(teams))
|
||||
for _, team := range teams {
|
||||
teamIds = append(teamIds, team.ID)
|
||||
teamIDs = append(teamIDs, team.ID)
|
||||
}
|
||||
actionsCountByTeamIDs, err := s.actionsRepo.GetActionsCountByTeamIDs(ctx, teamIds)
|
||||
actionsCountByTeamIDs, err := s.actionsRepo.GetActionsCountByTeamIDs(ctx, teamIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.answersRepo.GetAnswersByGameID(ctx, gameId)
|
||||
rows, err := s.answersRepo.GetAnswersByGameID(ctx, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -281,10 +281,10 @@ func (s *AnswerService) GetGameResults(ctx context.Context, gameId int) (*GameRe
|
||||
if _, ok := byCode[row.QuestionCode]; !ok {
|
||||
continue
|
||||
}
|
||||
if answerByTeamAndCode[row.TeamId] == nil {
|
||||
answerByTeamAndCode[row.TeamId] = make(map[string]AnswerScore, len(questions))
|
||||
if answerByTeamAndCode[row.TeamID] == nil {
|
||||
answerByTeamAndCode[row.TeamID] = make(map[string]AnswerScore, len(questions))
|
||||
}
|
||||
answerByTeamAndCode[row.TeamId][row.QuestionCode] = AnswerScore{
|
||||
answerByTeamAndCode[row.TeamID][row.QuestionCode] = AnswerScore{
|
||||
QuestionCode: row.QuestionCode,
|
||||
Text: row.Text,
|
||||
Score: row.Score,
|
||||
|
||||
Reference in New Issue
Block a user