fix names

This commit is contained in:
2026-10-01 13:13:03 +07:00
parent 76af14cb96
commit f462bc6a03
24 changed files with 213 additions and 213 deletions
+40 -40
View File
@@ -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,
@@ -38,7 +38,7 @@ func (s *Service) Create(ctx context.Context, gameID, teamID int, password strin
return nil, ErrInvalidReview
}
team, err := s.teams.GetTeamByID(ctx, teamID)
if err != nil || team.GameId != gameID || team.Password != password || team.ParticipationStatus == "cancelled" {
if err != nil || team.GameID != gameID || team.Password != password || team.ParticipationStatus == "cancelled" {
return nil, teams_repo.ErrTeamNotFound
}
game, err := s.games.GetGameByID(ctx, gameID)
+10 -10
View File
@@ -49,7 +49,7 @@ func (s *GameService) AddGame(
description string,
location *string,
startAt time.Time,
scenarioId int32,
scenarioID int32,
format string,
) (int, error) {
if format == "" {
@@ -58,7 +58,7 @@ func (s *GameService) AddGame(
if format != "online" && format != "offline" {
return 0, errors.New("Формат игры должен быть online или offline")
}
id, err := s.gamesRepo.AddGame(ctx, name, description, location, startAt, scenarioId, format)
id, err := s.gamesRepo.AddGame(ctx, name, description, location, startAt, scenarioID, format)
if err != nil {
return 0, err
}
@@ -80,7 +80,7 @@ func (s *GameService) GetGameMedia(ctx context.Context, id int) (*game_model.Gam
return nil, err
}
gameResult := game_model.MapGame(game, s.domain)
gameResult.Scenario, err = s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
gameResult.Scenario, err = s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioID)
if err != nil {
return nil, err
}
@@ -95,7 +95,7 @@ func (s *GameService) GetFullGame(
if err != nil {
return nil, err
}
scenario, err := s.scenariosRepo.GetScenarioByID(ctx, game.ScenarioId)
scenario, err := s.scenariosRepo.GetScenarioByID(ctx, game.ScenarioID)
if err != nil {
return nil, err
}
@@ -108,17 +108,17 @@ func (s *GameService) GetFullGame(
res := game_model.MapGame(game, s.domain)
teamIds := make([]int, 0, len(game.Teams))
teamIDs := make([]int, 0, len(game.Teams))
for _, team := range game.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
}
needApplicationsByTeamIDs, err := s.applicationsRepo.GetApplicationsByTeamIDsAndState(ctx, teamIds, "need")
needApplicationsByTeamIDs, err := s.applicationsRepo.GetApplicationsByTeamIDsAndState(ctx, teamIDs, "need")
if err != nil {
return nil, err
}
@@ -155,7 +155,7 @@ func (s *GameService) UpdateGame(
description string,
location *string,
startAt time.Time,
scenarioId int32,
scenarioID int32,
format string,
) error {
if format == "" {
@@ -168,7 +168,7 @@ func (s *GameService) UpdateGame(
if format != "online" && format != "offline" {
return errors.New("Формат игры должен быть online или offline")
}
return s.gamesRepo.UpdateGame(ctx, id, name, description, location, startAt, scenarioId, format)
return s.gamesRepo.UpdateGame(ctx, id, name, description, location, startAt, scenarioID, format)
}
func (s *GameService) StartGame(ctx context.Context, id int) error {
+22 -22
View File
@@ -45,12 +45,12 @@ func NewGameplayService(
}
}
func (s *GameplayService) GiveTeamApplications(ctx context.Context, teamId int, name string) error {
return s.applicationsRepo.UpdateApplicationStatus(ctx, teamId, name, "done")
func (s *GameplayService) GiveTeamApplications(ctx context.Context, teamID int, name string) error {
return s.applicationsRepo.UpdateApplicationStatus(ctx, teamID, name, "done")
}
func (s *GameplayService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_model.Game, []actions_repo.Action, error) {
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
func (s *GameplayService) GetTeamActions(ctx context.Context, teamID int, password string) (*storytelling.Story, *game_model.Game, []actions_repo.Action, error) {
team, err := s.teamsRepo.GetTeamByID(ctx, teamID)
if err != nil {
return nil, nil, nil, err
}
@@ -59,7 +59,7 @@ func (s *GameplayService) GetTeamActions(ctx context.Context, teamId int, passwo
return nil, 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, nil, err
}
@@ -67,12 +67,12 @@ func (s *GameplayService) GetTeamActions(ctx context.Context, teamId int, passwo
return &storytelling.Story{}, game_model.MapGame(game, s.domain), nil, nil
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamID)
if err != nil {
return nil, nil, nil, err
}
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioID)
if err != nil {
return nil, nil, nil, err
}
@@ -86,8 +86,8 @@ func (s *GameplayService) GetTeamActions(ctx context.Context, teamId int, passwo
return story, game_model.MapGame(game, s.domain), actions, nil
}
func (s *GameplayService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string, viaMCP bool) error {
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
func (s *GameplayService) AddTeamAction(ctx context.Context, teamID int, password string, actionCode string, viaMCP bool) error {
team, err := s.teamsRepo.GetTeamByID(ctx, teamID)
if err != nil {
return err
}
@@ -96,27 +96,27 @@ func (s *GameplayService) AddTeamAction(ctx context.Context, teamId int, passwor
return teams_repo.ErrTeamNotFound
}
_, err = s.actionsRepo.AddAction(ctx, teamId, actionCode, viaMCP)
_, err = s.actionsRepo.AddAction(ctx, teamID, actionCode, viaMCP)
if err != nil {
return err
}
if team.ParticipationStatus == "pending" {
if err := s.teamsRepo.ConfirmParticipationByFirstAction(ctx, teamId); err != nil {
if err := s.teamsRepo.ConfirmParticipationByFirstAction(ctx, teamID); 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
}
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamID)
if err != nil {
return err
}
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioID)
if err != nil {
return err
}
@@ -132,7 +132,7 @@ func (s *GameplayService) AddTeamAction(ctx context.Context, teamId int, passwor
for _, application := range lastPlace.Applications {
app := newApplication(application, s.domain)
app.Name = s.cleaner.ClearText(app.Name)
if _, err := s.applicationsRepo.AddApplication(ctx, teamId, app.Name, app.Image, app.FileType); err != nil {
if _, err := s.applicationsRepo.AddApplication(ctx, teamID, app.Name, app.Image, app.FileType); err != nil {
return err
}
}
@@ -140,23 +140,23 @@ func (s *GameplayService) AddTeamAction(ctx context.Context, teamId int, passwor
return nil
}
func (s *GameplayService) DeleteLastTeamAction(ctx context.Context, teamId int) error {
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
func (s *GameplayService) DeleteLastTeamAction(ctx context.Context, teamID 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
}
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamID)
if err != nil {
return err
}
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioID)
if err != nil {
return err
}
@@ -170,10 +170,10 @@ func (s *GameplayService) DeleteLastTeamAction(ctx context.Context, teamId int)
lastPlace := teamStory.Places[len(teamStory.Places)-1]
for _, application := range lastPlace.Applications {
if err := s.applicationsRepo.DeleteApplicationByTeamIdAndName(ctx, teamId, application.Name); err != nil {
if err := s.applicationsRepo.DeleteApplicationByTeamIDAndName(ctx, teamID, application.Name); err != nil {
return err
}
}
return s.actionsRepo.DeleteLastActionByTeamId(ctx, teamId)
return s.actionsRepo.DeleteLastActionByTeamID(ctx, teamID)
}
+3 -3
View File
@@ -31,13 +31,13 @@ const defaultCallTimeout = 10 * time.Second
// *gameplay_service.GameplayService; интерфейс позволяет тестировать сервис
// без БД.
type GamePlayer interface {
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_model.Game, []actions_repo.Action, error)
AddTeamAction(ctx context.Context, teamId int, password, actionCode string, viaMCP bool) error
GetTeamActions(ctx context.Context, teamID int, password string) (*storytelling.Story, *game_model.Game, []actions_repo.Action, error)
AddTeamAction(ctx context.Context, teamID int, password, actionCode string, viaMCP bool) error
}
// AnswerSubmitter сохраняет ответы команды независимо от прохождения истории.
type AnswerSubmitter interface {
SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []answer_service.Answer) error
SubmitTeamAnswers(ctx context.Context, teamID int, password string, answers []answer_service.Answer) error
}
// MCPService собирает MCP-сервер с игровыми инструментами. Сервис не
+36 -36
View File
@@ -17,8 +17,8 @@ import (
// scenariosRepository — граница доступа к данным сценариев, реализуемая
// *scenarios_repo.ScenariosRepo (интерфейс — для тестов без БД).
type scenariosRepository interface {
AddScenario(ctx context.Context, name string, authorId int) (int, error)
GetScenariosByAuthorID(ctx context.Context, authorId int) ([]*repos.Scenario, error)
AddScenario(ctx context.Context, name string, authorID int) (int, error)
GetScenariosByAuthorID(ctx context.Context, authorID int) ([]*repos.Scenario, error)
GetScenariosByStatus(ctx context.Context, status string) ([]*repos.Scenario, error)
GetScenarioByID(ctx context.Context, id int) (*repos.Scenario, error)
UpdateScenarioByID(ctx context.Context, id int, name string, description string, image string) error
@@ -55,9 +55,9 @@ func NewScenarioService(
func (s *ScenarioService) AddScenario(
ctx context.Context,
name string,
authorId int,
authorID int,
) (int, error) {
id, err := s.scenariosRepo.AddScenario(ctx, name, authorId)
id, err := s.scenariosRepo.AddScenario(ctx, name, authorID)
if err != nil {
return 0, err
}
@@ -66,9 +66,9 @@ func (s *ScenarioService) AddScenario(
func (s *ScenarioService) GetScenariosByAuthorID(
ctx context.Context,
authorId int,
authorID int,
) ([]*Scenario, error) {
scenarios, err := s.scenariosRepo.GetScenariosByAuthorID(ctx, authorId)
scenarios, err := s.scenariosRepo.GetScenariosByAuthorID(ctx, authorID)
if err != nil {
return nil, err
}
@@ -113,10 +113,10 @@ func (s *ScenarioService) UpdateScenarioByID(
name string,
description string,
image string,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
return s.scenariosRepo.UpdateScenarioByID(ctx, id, name, description, image)
@@ -137,7 +137,7 @@ var ErrScenarioNotOwner = errors.New("Сценарий принадлежит д
func (s *ScenarioService) getScenarioForChange(
ctx context.Context,
id int,
actorId int,
actorID int,
isAdmin bool,
) (*repos.Scenario, error) {
scenario, err := s.scenariosRepo.GetScenarioByID(ctx, id)
@@ -150,7 +150,7 @@ func (s *ScenarioService) getScenarioForChange(
if isAdmin {
return scenario, nil
}
if scenario.Author == nil || scenario.Author.ID != actorId {
if scenario.Author == nil || scenario.Author.ID != actorID {
return nil, ErrScenarioNotOwner
}
return scenario, nil
@@ -160,10 +160,10 @@ func (s *ScenarioService) UpdateScenarioStatusByID(
ctx context.Context,
id int,
status string,
actorId int,
actorID int,
isAdmin bool,
) error {
scenario, err := s.getScenarioForChange(ctx, id, actorId, isAdmin)
scenario, err := s.getScenarioForChange(ctx, id, actorID, isAdmin)
if err != nil {
return err
}
@@ -190,10 +190,10 @@ func (s *ScenarioService) UpdateScenarioStatusByID(
func (s *ScenarioService) DeleteScenarioByID(
ctx context.Context,
id int,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
// Guard в SQL защищает от гонки «чтение статуса → запись»: не-админ не
@@ -212,10 +212,10 @@ func (s *ScenarioService) AddScenarioPlace(
ctx context.Context,
id int,
place *storytelling.Place,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -234,10 +234,10 @@ func (s *ScenarioService) UpdateScenarioPlace(
id int,
code string,
place *storytelling.Place,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -257,10 +257,10 @@ func (s *ScenarioService) DeleteScenarioPlace(
ctx context.Context,
id int,
code string,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -277,8 +277,8 @@ func (s *ScenarioService) DeleteScenarioPlace(
}
// UpdateScenarioBackground устанавливает фон; пустое значение снимает его с дела.
func (s *ScenarioService) UpdateScenarioBackground(ctx context.Context, id int, background string, actorId int, isAdmin bool) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
func (s *ScenarioService) UpdateScenarioBackground(ctx context.Context, id int, background string, actorID int, isAdmin bool) error {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
if background != "" && file_storage.FileType(background) != "image" {
@@ -297,10 +297,10 @@ func (s *ScenarioService) UpdateScenarioIntro(
ctx context.Context,
id int,
introduction *storytelling.Introduction,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -311,8 +311,8 @@ func (s *ScenarioService) UpdateScenarioIntro(
return s.updateStory(ctx, id, story)
}
func (s *ScenarioService) UpdateScenarioConclusion(ctx context.Context, id int, conclusion *storytelling.Conclusion, actorId int, isAdmin bool) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
func (s *ScenarioService) UpdateScenarioConclusion(ctx context.Context, id int, conclusion *storytelling.Conclusion, actorID int, isAdmin bool) error {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -328,10 +328,10 @@ func (s *ScenarioService) AddScenarioQuestion(
ctx context.Context,
id int,
question *storytelling.Question,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -349,10 +349,10 @@ func (s *ScenarioService) UpdateScenarioQuestion(
id int,
code string,
question *storytelling.Question,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -373,10 +373,10 @@ func (s *ScenarioService) DeleteScenarioQuestion(
ctx context.Context,
id int,
code string,
actorId int,
actorID int,
isAdmin bool,
) error {
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
return err
}
story, err := s.getStory(ctx, id)
@@ -404,10 +404,10 @@ func (s *ScenarioService) getStory(ctx context.Context, id int) (*storytelling.S
func (s *ScenarioService) DownloadArchive(
ctx context.Context,
id int,
actorId int,
actorID int,
isAdmin bool,
) ([]byte, string, error) {
scenario, err := s.getScenarioForChange(ctx, id, actorId, isAdmin)
scenario, err := s.getScenarioForChange(ctx, id, actorID, isAdmin)
if err != nil {
return nil, "", err
}
@@ -435,7 +435,7 @@ func (s *ScenarioService) DownloadArchive(
func (s *ScenarioService) UploadArchive(
ctx context.Context,
data []byte,
authorId int,
authorID int,
) (int, error) {
bundle, err := s.scenarioArchive.Unpack(data)
if err != nil {
@@ -522,7 +522,7 @@ func (s *ScenarioService) UploadArchive(
return 0, err
}
id, err := s.scenariosRepo.AddScenario(ctx, scenario.Name, authorId)
id, err := s.scenariosRepo.AddScenario(ctx, scenario.Name, authorID)
if err != nil {
return 0, err
}
@@ -165,7 +165,7 @@ func newFakeScenariosRepo() *fakeScenariosRepo {
}
}
func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorId int) (int, error) {
func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorID int) (int, error) {
r.mu.Lock()
defer r.mu.Unlock()
if r.addErr != nil {
@@ -177,18 +177,18 @@ func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorId
ID: r.nextID,
Name: name,
Description: &description,
Author: &repos.User{ID: authorId},
Author: &repos.User{ID: authorID},
Status: "draft",
}
return r.nextID, nil
}
func (r *fakeScenariosRepo) GetScenariosByAuthorID(_ context.Context, authorId int) ([]*repos.Scenario, error) {
func (r *fakeScenariosRepo) GetScenariosByAuthorID(_ context.Context, authorID int) ([]*repos.Scenario, error) {
r.mu.Lock()
defer r.mu.Unlock()
var res []*repos.Scenario
for _, s := range r.byID {
if s.Author != nil && s.Author.ID == authorId {
if s.Author != nil && s.Author.ID == authorID {
res = append(res, s)
}
}
+8 -8
View File
@@ -43,8 +43,8 @@ func NewTeamService(
func (s *TeamService) AddTeam(
ctx context.Context,
creatorId int,
gameId int,
creatorID int,
gameID int,
name string,
captainEmail string,
) (*game_model.Team, error) {
@@ -56,11 +56,11 @@ func (s *TeamService) AddTeam(
if err != nil {
return nil, err
}
game, err := s.gamesRepo.GetGameByID(ctx, gameId)
game, err := s.gamesRepo.GetGameByID(ctx, gameID)
if err != nil {
return nil, err
}
id, err := s.teamsRepo.AddTeamWithParticipation(ctx, creatorId, gameId, name, password, captainEmail, !time.Now().Before(game.StartAt.Add(-24*time.Hour)))
id, err := s.teamsRepo.AddTeamWithParticipation(ctx, creatorID, gameID, name, password, captainEmail, !time.Now().Before(game.StartAt.Add(-24*time.Hour)))
if err != nil {
return nil, err
}
@@ -70,12 +70,12 @@ func (s *TeamService) AddTeam(
}, nil
}
func (s *TeamService) UpdateTeam(ctx context.Context, teamId int, name string) error {
return s.teamsRepo.UpdateTeam(ctx, teamId, name)
func (s *TeamService) UpdateTeam(ctx context.Context, teamID int, name string) error {
return s.teamsRepo.UpdateTeam(ctx, teamID, name)
}
func (s *TeamService) DeleteTeam(ctx context.Context, teamId int) error {
return s.teamsRepo.DeleteTeam(ctx, teamId)
func (s *TeamService) DeleteTeam(ctx context.Context, teamID int) error {
return s.teamsRepo.DeleteTeam(ctx, teamID)
}
func (s *TeamService) RegisterTeam(ctx context.Context, gameID int, deliveryID string, registration Registration) (int, error) {
+12 -12
View File
@@ -48,9 +48,9 @@ type usersRepository interface {
GetUserByEmail(ctx context.Context, email string) (*repos.User, error)
GetUserByID(ctx context.Context, id int) (*repos.User, error)
GetUsers(ctx context.Context) ([]*repos.User, error)
AddUserRole(ctx context.Context, userId int, role string) error
DeleteUserRole(ctx context.Context, userId int, role string) error
DeleteUser(ctx context.Context, userId int) error
AddUserRole(ctx context.Context, userID int, role string) error
DeleteUserRole(ctx context.Context, userID int, role string) error
DeleteUser(ctx context.Context, userID int) error
}
type UsersService struct {
@@ -165,17 +165,17 @@ func (s *UsersService) AddUser(
// access-токена не должен мочь удалить чужой аккаунт.
func (s *UsersService) DeleteAccount(
ctx context.Context,
userId int,
userID int,
password string,
) error {
user, err := s.usersRepo.GetUserByID(ctx, userId)
user, err := s.usersRepo.GetUserByID(ctx, userID)
if err != nil {
return err
}
if err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)); err != nil {
return errors.New("Неверный пароль")
}
return s.usersRepo.DeleteUser(ctx, userId)
return s.usersRepo.DeleteUser(ctx, userID)
}
func (s *UsersService) RefreshPassword(
@@ -336,9 +336,9 @@ func (s *UsersService) GetUsers(
func (s *UsersService) GetUserByID(
ctx context.Context,
userId int,
userID int,
) (*repos.User, error) {
user, err := s.usersRepo.GetUserByID(ctx, userId)
user, err := s.usersRepo.GetUserByID(ctx, userID)
if err != nil {
return nil, err
}
@@ -347,24 +347,24 @@ func (s *UsersService) GetUserByID(
func (s *UsersService) AddUserRole(
ctx context.Context,
userId int,
userID int,
role string,
) error {
if !slices.Contains(roles.AllRoles, role) {
return fmt.Errorf("role %s not support", role)
}
return s.usersRepo.AddUserRole(ctx, userId, role)
return s.usersRepo.AddUserRole(ctx, userID, role)
}
func (s *UsersService) DeleteUserRole(
ctx context.Context,
userId int,
userID int,
role string,
) error {
if !slices.Contains(roles.AllRoles, role) {
return fmt.Errorf("role %s not support", role)
}
return s.usersRepo.DeleteUserRole(ctx, userId, role)
return s.usersRepo.DeleteUserRole(ctx, userID, role)
}
var (
@@ -117,14 +117,14 @@ func (r *fakeRepo) AddUserRole(_ context.Context, _ int, _ string) error { retur
func (r *fakeRepo) DeleteUserRole(_ context.Context, _ int, _ string) error { return nil }
func (r *fakeRepo) DeleteUser(_ context.Context, userId int) error {
func (r *fakeRepo) DeleteUser(_ context.Context, userID int) error {
r.mu.Lock()
defer r.mu.Unlock()
u, ok := r.byID[userId]
u, ok := r.byID[userID]
if !ok {
return users_repo.ErrUserNotFound
}
delete(r.byID, userId)
delete(r.byID, userID)
delete(r.users, u.Email)
return nil
}