generated from VLADIMIR/template
updates proto
This commit is contained in:
+159
-153
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@ func (s *testStub) UploadScenarioArchive(_ context.Context, req *httpbody.HttpBo
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.uploaded = append([]byte(nil), req.Data...)
|
||||
return &proto.UploadScenarioArchiveRsp{Id: 42}, nil
|
||||
return &proto.UploadScenarioArchiveRsp{ID: 42}, nil
|
||||
}
|
||||
|
||||
func (s *testStub) DownloadScenarioArchive(ctx context.Context, _ *proto.DownloadScenarioArchiveReq) (*httpbody.HttpBody, error) {
|
||||
@@ -81,7 +81,7 @@ func (s *testStub) getUploaded() []byte {
|
||||
}
|
||||
|
||||
func (s *testStub) DownloadTeamQR(ctx context.Context, req *proto.GetGameReq) (*httpbody.HttpBody, error) {
|
||||
if req.Id != 7 {
|
||||
if req.ID != 7 {
|
||||
return nil, status.Error(codes.NotFound, "Игра не найдена")
|
||||
}
|
||||
data, err := team_qr_pdf.Generate([]team_qr_pdf.Card{{Name: "Знатоки", URL: "https://example.org/team-story/1?password=test"}})
|
||||
@@ -204,8 +204,8 @@ func TestGatewayUploadRawZip(t *testing.T) {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status = %d, body = %s", resp.StatusCode, body)
|
||||
}
|
||||
if !strings.Contains(string(body), `"id":42`) {
|
||||
t.Errorf("ответ = %s, want id 42", body)
|
||||
if !strings.Contains(string(body), `"ID":42`) {
|
||||
t.Errorf("ответ = %s, want ID 42", body)
|
||||
}
|
||||
if got := stub.getUploaded(); !bytes.Equal(got, raw) {
|
||||
t.Errorf("сервер получил %q, want %q", got, raw)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+8
-2
@@ -81,7 +81,7 @@ Handler не содержит SQL, транзакций, правил перех
|
||||
|
||||
```go
|
||||
func (s *server) GetGame(ctx context.Context, req *proto.GetGameReq) (*proto.GetGameRsp, error) {
|
||||
game, err := s.gameService.Get(ctx, req.GetId(), currentUserID(ctx))
|
||||
game, err := s.gameService.Get(ctx, req.GetID(), currentUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func (s *server) GetGame(ctx context.Context, req *proto.GetGameReq) (*proto.Get
|
||||
|
||||
// game_mapper.go
|
||||
func mapGetGameResponse(game *Game) *proto.GetGameRsp {
|
||||
return &proto.GetGameRsp{Game: &proto.Game{Id: int32(game.ID), Name: game.Name}}
|
||||
return &proto.GetGameRsp{Game: &proto.Game{ID: int32(game.ID), Name: game.Name}}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -176,6 +176,12 @@ SQL держи рядом с методом, которому он нужен.
|
||||
|
||||
- Protobuf — внешний транспортный контракт. Сгенерированные файлы в `proto/`
|
||||
и Swagger вручную не редактируй.
|
||||
- В protobuf используй `ID`, `<name>ID` и `URL` для полей с соответствующими
|
||||
аббревиатурами. Генератор тогда создаёт `ID`, `GameID`, `URL` в Go и
|
||||
`ID`, `gameID`, `URL` в TypeScript.
|
||||
- Поля каждого `message` объявляй в порядке возрастания номеров. Номера уже
|
||||
опубликованных полей не меняй и не переиспользуй; удалённые номера оставляй
|
||||
зарезервированными.
|
||||
- Новые HTTP-методы добавляй через `api/main.proto`, затем запускай генерацию
|
||||
`make generate`.
|
||||
- Преобразование `proto ↔ domain/storage` находится в `app` или пакете,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func (s *server) GetTeamAnswers(ctx context.Context, req *proto.GetTeamAnswersReq) (*proto.GetTeamAnswersRsp, error) {
|
||||
answers, err := s.answerService.GetTeamAnswers(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Password,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -30,7 +30,7 @@ func (s *server) GetTeamAnswers(ctx context.Context, req *proto.GetTeamAnswersRe
|
||||
func (s *server) SubmitTeamAnswers(ctx context.Context, req *proto.SubmitTeamAnswersReq) (*proto.SubmitTeamAnswersRsp, error) {
|
||||
err := s.answerService.SubmitTeamAnswers(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Password,
|
||||
convertAnswers(req.Answers),
|
||||
)
|
||||
@@ -60,7 +60,7 @@ func (s *server) SetTeamAnswerScore(ctx context.Context, req *proto.SetTeamAnswe
|
||||
|
||||
err := s.answerService.SetTeamAnswerScore(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.QuestionCode,
|
||||
score,
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestChangeUserPasswordAccess(t *testing.T) {
|
||||
{ctxWithClaims("author"), codes.PermissionDenied},
|
||||
{ctxWithClaims("organizer"), codes.PermissionDenied},
|
||||
} {
|
||||
_, err := s.ChangeUserPassword(tc.ctx, &proto.ChangeUserPasswordReq{Id: 2, NewPassword: "123456789012"})
|
||||
_, err := s.ChangeUserPassword(tc.ctx, &proto.ChangeUserPasswordReq{ID: 2, NewPassword: "123456789012"})
|
||||
if status.Code(err) != tc.want {
|
||||
t.Errorf("code = %v, want %v", status.Code(err), tc.want)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func TestChangeUserPasswordTransports(t *testing.T) {
|
||||
}
|
||||
rpcCtx = metadata.NewOutgoingContext(ctx, metadata.Pairs("authorization", "Bearer "+token))
|
||||
}
|
||||
_, err := client.ChangeUserPassword(rpcCtx, &proto.ChangeUserPasswordReq{Id: tc.id, NewPassword: tc.password})
|
||||
_, err := client.ChangeUserPassword(rpcCtx, &proto.ChangeUserPasswordReq{ID: tc.id, NewPassword: tc.password})
|
||||
if status.Code(err) != tc.code {
|
||||
t.Fatalf("gRPC = %v, want %v", err, tc.code)
|
||||
}
|
||||
|
||||
+11
-11
@@ -15,34 +15,34 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 {
|
||||
if req == nil || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
game, err := s.gameService.GetFullGame(ctx, int(req.GameId))
|
||||
game, err := s.gameService.GetFullGame(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameId), "organizer_desk", 1); err != nil {
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameID), "organizer_desk", 1); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить карту")
|
||||
}
|
||||
for _, team := range game.Teams {
|
||||
if team.ParticipationStatus == "cancelled" {
|
||||
continue
|
||||
}
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameId), "team", team.ID); err != nil {
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameID), "team", team.ID); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить карту")
|
||||
}
|
||||
}
|
||||
screens, err := s.screenRepo.ListByGame(ctx, int(req.GameId))
|
||||
screens, err := s.screenRepo.ListByGame(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить экраны")
|
||||
}
|
||||
for _, screen := range screens {
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameId), "screen", screen.ID); err != nil {
|
||||
if err := s.mapRepo.Ensure(ctx, int(req.GameID), "screen", screen.ID); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить карту")
|
||||
}
|
||||
}
|
||||
items, err := s.mapRepo.List(ctx, int(req.GameId))
|
||||
items, err := s.mapRepo.List(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить карту")
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
}
|
||||
continue
|
||||
}
|
||||
mapped := &proto.MapItem{Kind: item.Kind, ItemId: int32(item.ItemID), X: int32(item.X), Y: int32(item.Y), Hidden: item.Hidden}
|
||||
mapped := &proto.MapItem{Kind: item.Kind, ItemID: int32(item.ItemID), X: int32(item.X), Y: int32(item.Y), Hidden: item.Hidden}
|
||||
if item.Kind == "team" {
|
||||
mapped.Label = teamNames[item.ItemID]
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
mapped.Label = "Стол организаторов"
|
||||
}
|
||||
if state := screenStates[item.ItemID]; item.Kind == "screen" && state != nil {
|
||||
mapped.Label = "Экран " + state.Id
|
||||
mapped.Label = "Экран " + state.ID
|
||||
mapped.Status = state.Status
|
||||
mapped.SoundEnabled = state.SoundEnabled
|
||||
}
|
||||
@@ -87,10 +87,10 @@ func (s *server) UpdateGameMapItem(ctx context.Context, req *proto.UpdateGameMap
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 || req.ItemId <= 0 || (req.Kind != "team" && req.Kind != "screen" && req.Kind != "organizer_desk") {
|
||||
if req == nil || req.GameID <= 0 || req.ItemID <= 0 || (req.Kind != "team" && req.Kind != "screen" && req.Kind != "organizer_desk") {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный объект карты")
|
||||
}
|
||||
if err := s.mapRepo.Update(ctx, game_map_repo.Item{GameID: int(req.GameId), Kind: req.Kind, ItemID: int(req.ItemId), X: int(req.X), Y: int(req.Y), Hidden: req.Hidden}); err != nil {
|
||||
if err := s.mapRepo.Update(ctx, game_map_repo.Item{GameID: int(req.GameID), Kind: req.Kind, ItemID: int(req.ItemID), X: int(req.X), Y: int(req.Y), Hidden: req.Hidden}); err != nil {
|
||||
if errors.Is(err, game_map_repo.ErrItemNotFound) {
|
||||
return nil, status.Error(codes.NotFound, "объект карты не найден")
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func mapGame(
|
||||
teams = append(teams, mapTeamDetails(team))
|
||||
}
|
||||
return &proto.Game{
|
||||
Id: int32(o.ID),
|
||||
ID: int32(o.ID),
|
||||
Name: o.Name,
|
||||
Description: o.Description,
|
||||
Location: location,
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func mapGameReview(r *game_reviews_repo.Review) *proto.GameReview {
|
||||
return &proto.GameReview{Id: int32(r.ID), GameId: int32(r.GameID), TeamId: int32(r.TeamID), TeamName: r.TeamName, Rating: r.Rating, Text: r.Text, Status: r.Status, CreatedAt: timestamppb.New(r.CreatedAt), GameName: r.GameName}
|
||||
return &proto.GameReview{ID: int32(r.ID), GameID: int32(r.GameID), TeamID: int32(r.TeamID), TeamName: r.TeamName, Rating: r.Rating, Text: r.Text, Status: r.Status, CreatedAt: timestamppb.New(r.CreatedAt), GameName: r.GameName}
|
||||
}
|
||||
|
||||
func mapGameReviews(reviews []*game_reviews_repo.Review) []*proto.GameReview {
|
||||
@@ -24,7 +24,7 @@ func mapGameReviews(reviews []*game_reviews_repo.Review) []*proto.GameReview {
|
||||
}
|
||||
|
||||
func (s *server) CreateGameReview(ctx context.Context, req *proto.CreateGameReviewReq) (*proto.CreateGameReviewRsp, error) {
|
||||
review, err := s.reviewService.Create(ctx, int(req.GameId), int(req.TeamId), req.Password, req.Rating, req.Text)
|
||||
review, err := s.reviewService.Create(ctx, int(req.GameID), int(req.TeamID), req.Password, req.Rating, req.Text)
|
||||
if err != nil {
|
||||
return &proto.CreateGameReviewRsp{Error: err.Error()}, nil
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (s *server) CreateGameReview(ctx context.Context, req *proto.CreateGameRevi
|
||||
}
|
||||
|
||||
func (s *server) GetGameReviews(ctx context.Context, req *proto.GetGameReviewsReq) (*proto.GetGameReviewsRsp, error) {
|
||||
reviews, average, count, err := s.reviewService.List(ctx, int(req.GameId), false)
|
||||
reviews, average, count, err := s.reviewService.List(ctx, int(req.GameID), false)
|
||||
if err != nil {
|
||||
return &proto.GetGameReviewsRsp{Error: err.Error()}, nil
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (s *server) GetGameReviews(ctx context.Context, req *proto.GetGameReviewsRe
|
||||
}
|
||||
|
||||
func (s *server) GetScenarioReviews(ctx context.Context, req *proto.GetScenarioReviewsReq) (*proto.GetGameReviewsRsp, error) {
|
||||
reviews, average, count, err := s.reviewService.ListByScenario(ctx, int(req.ScenarioId))
|
||||
reviews, average, count, err := s.reviewService.ListByScenario(ctx, int(req.ScenarioID))
|
||||
if err != nil {
|
||||
return &proto.GetGameReviewsRsp{Error: err.Error()}, nil
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (s *server) GetGameReviewsForModeration(ctx context.Context, req *proto.Get
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
reviews, average, count, err := s.reviewService.List(ctx, int(req.GameId), true)
|
||||
reviews, average, count, err := s.reviewService.List(ctx, int(req.GameID), true)
|
||||
if err != nil {
|
||||
return &proto.GetGameReviewsRsp{Error: err.Error()}, nil
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (s *server) ModerateGameReview(ctx context.Context, req *proto.ModerateGame
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
review, err := s.reviewService.Moderate(ctx, int(req.Id), req.Status)
|
||||
review, err := s.reviewService.Moderate(ctx, int(req.ID), req.Status)
|
||||
if err != nil {
|
||||
return &proto.ModerateGameReviewRsp{Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
+13
-13
@@ -36,7 +36,7 @@ func (s *server) AddGame(ctx context.Context, req *proto.AddGameReq) (*proto.Add
|
||||
req.Description,
|
||||
nilIfEmpty(req.Location),
|
||||
req.StartAt.AsTime(),
|
||||
req.ScenarioId,
|
||||
req.ScenarioID,
|
||||
req.Format,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -46,7 +46,7 @@ func (s *server) AddGame(ctx context.Context, req *proto.AddGameReq) (*proto.Add
|
||||
}
|
||||
|
||||
return &proto.AddGameRsp{
|
||||
Id: int32(id),
|
||||
ID: int32(id),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func (s *server) DeleteGame(ctx context.Context, req *proto.DeleteGameReq) (*pro
|
||||
|
||||
err := s.gameService.DeleteGame(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteGameRsp{
|
||||
@@ -81,7 +81,7 @@ func (s *server) GetGame(ctx context.Context, req *proto.GetGameReq) (*proto.Get
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
game, err := s.gameService.GetFullGame(ctx, int(req.Id))
|
||||
game, err := s.gameService.GetFullGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.GetGameRsp{
|
||||
Error: err.Error(),
|
||||
@@ -102,7 +102,7 @@ func (s *server) GetGameAnswers(ctx context.Context, req *proto.GetGameAnswersRe
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
gameAnswers, err := s.answerService.GetGameAnswers(ctx, int(req.GameId))
|
||||
gameAnswers, err := s.answerService.GetGameAnswers(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return &proto.GetGameAnswersRsp{
|
||||
Error: err.Error(),
|
||||
@@ -124,7 +124,7 @@ func (s *server) GetGameResults(ctx context.Context, req *proto.GetGameResultsRe
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
results, err := s.answerService.GetGameResults(ctx, int(req.GameId))
|
||||
results, err := s.answerService.GetGameResults(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return &proto.GetGameResultsRsp{
|
||||
Error: err.Error(),
|
||||
@@ -173,12 +173,12 @@ func (s *server) UpdateGame(ctx context.Context, req *proto.UpdateGameReq) (*pro
|
||||
|
||||
err := s.gameService.UpdateGame(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Name,
|
||||
req.Description,
|
||||
nilIfEmpty(req.Location),
|
||||
req.StartAt.AsTime(),
|
||||
req.ScenarioId,
|
||||
req.ScenarioID,
|
||||
req.Format,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -199,7 +199,7 @@ func (s *server) StartGame(ctx context.Context, req *proto.StartGameReq) (*proto
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.StartGame(ctx, int(req.Id))
|
||||
err := s.gameService.StartGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.StartGameRsp{
|
||||
Error: err.Error(),
|
||||
@@ -218,7 +218,7 @@ func (s *server) PauseGame(ctx context.Context, req *proto.PauseGameReq) (*proto
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.PauseGame(ctx, int(req.Id))
|
||||
err := s.gameService.PauseGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.PauseGameRsp{
|
||||
Error: err.Error(),
|
||||
@@ -237,7 +237,7 @@ func (s *server) PlayGame(ctx context.Context, req *proto.PlayGameReq) (*proto.P
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.PlayGame(ctx, int(req.Id))
|
||||
err := s.gameService.PlayGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.PlayGameRsp{
|
||||
Error: err.Error(),
|
||||
@@ -256,7 +256,7 @@ func (s *server) FinishGame(ctx context.Context, req *proto.FinishGameReq) (*pro
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.FinishGame(ctx, int(req.Id))
|
||||
err := s.gameService.FinishGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.FinishGameRsp{
|
||||
Error: err.Error(),
|
||||
@@ -275,7 +275,7 @@ func (s *server) ResetGame(ctx context.Context, req *proto.ResetGameReq) (*proto
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.ResetGame(ctx, int(req.Id))
|
||||
err := s.gameService.ResetGame(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.ResetGameRsp{
|
||||
Error: err.Error(),
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestMapTeamResults(t *testing.T) {
|
||||
t.Fatalf("len(mapTeamResults) = %d, want 1", len(got))
|
||||
}
|
||||
row := got[0]
|
||||
if row.Team == nil || row.Team.Id != 1 || row.Team.Name != "Команда А" {
|
||||
if row.Team == nil || row.Team.ID != 1 || row.Team.Name != "Команда А" {
|
||||
t.Fatalf("row.Team = %+v, want id 1, name Команда А", row.Team)
|
||||
}
|
||||
// actionsCount продублирован на уровне строки таблицы.
|
||||
|
||||
@@ -31,7 +31,7 @@ func (s *server) DownloadScenarioArchive(ctx context.Context, req *proto.Downloa
|
||||
|
||||
data, name, err := s.scenarioService.DownloadArchive(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
)
|
||||
@@ -85,7 +85,7 @@ func (s *server) UploadScenarioArchive(ctx context.Context, req *httpbody.HttpBo
|
||||
}, nil
|
||||
}
|
||||
return &proto.UploadScenarioArchiveRsp{
|
||||
Id: int32(id),
|
||||
ID: int32(id),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *server) AddScenarioPlace(ctx context.Context, req *proto.AddScenarioPla
|
||||
|
||||
err := s.scenarioService.AddScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
convertPlace(req.Place),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -46,7 +46,7 @@ func (s *server) UpdateScenarioPlace(ctx context.Context, req *proto.UpdateScena
|
||||
|
||||
err := s.scenarioService.UpdateScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Code,
|
||||
convertPlace(req.Place),
|
||||
claims.UserID,
|
||||
@@ -72,7 +72,7 @@ func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScena
|
||||
|
||||
err := s.scenarioService.DeleteScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Code,
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -97,7 +97,7 @@ func (s *server) AddScenarioQuestion(ctx context.Context, req *proto.AddScenario
|
||||
|
||||
err := s.scenarioService.AddScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
convertQuestion(req.Question),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -122,7 +122,7 @@ func (s *server) UpdateScenarioQuestion(ctx context.Context, req *proto.UpdateSc
|
||||
|
||||
err := s.scenarioService.UpdateScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Code,
|
||||
convertQuestion(req.Question),
|
||||
claims.UserID,
|
||||
@@ -148,7 +148,7 @@ func (s *server) DeleteScenarioQuestion(ctx context.Context, req *proto.DeleteSc
|
||||
|
||||
err := s.scenarioService.DeleteScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Code,
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -173,7 +173,7 @@ func (s *server) UpdateScenarioBackground(ctx context.Context, req *proto.Update
|
||||
|
||||
err := s.scenarioService.UpdateScenarioBackground(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Background,
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -198,7 +198,7 @@ func (s *server) UpdateScenarioIntro(ctx context.Context, req *proto.UpdateScena
|
||||
|
||||
err := s.scenarioService.UpdateScenarioIntro(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
convertIntroduction(req.Introduction),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
@@ -220,7 +220,7 @@ func (s *server) UpdateScenarioConclusion(ctx context.Context, req *proto.Update
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if err := s.scenarioService.UpdateScenarioConclusion(ctx, int(req.Id), convertConclusion(req.Conclusion), claims.UserID, roles.HasRole(claims, roles.Admin)); err != nil {
|
||||
if err := s.scenarioService.UpdateScenarioConclusion(ctx, int(req.ID), convertConclusion(req.Conclusion), claims.UserID, roles.HasRole(claims, roles.Admin)); err != nil {
|
||||
return &proto.UpdateScenarioConclusionRsp{Error: err.Error()}, nil
|
||||
}
|
||||
return &proto.UpdateScenarioConclusionRsp{}, nil
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s *server) AddScenario(ctx context.Context, req *proto.AddScenarioReq) (*p
|
||||
}, nil
|
||||
}
|
||||
return &proto.AddScenarioRsp{
|
||||
Id: int32(id),
|
||||
ID: int32(id),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (s *server) GetFullScenario(ctx context.Context, req *proto.GetScenarioReq)
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, int(req.Id))
|
||||
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.GetScenarioRsp{
|
||||
Error: err.Error(),
|
||||
@@ -90,7 +90,7 @@ func (s *server) GetFullScenario(ctx context.Context, req *proto.GetScenarioReq)
|
||||
}
|
||||
|
||||
func (s *server) GetScenario(ctx context.Context, req *proto.GetScenarioReq) (*proto.GetScenarioRsp, error) {
|
||||
scenario, err := s.scenarioService.GetScenarioByID(ctx, int(req.Id))
|
||||
scenario, err := s.scenarioService.GetScenarioByID(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.GetScenarioRsp{
|
||||
Error: err.Error(),
|
||||
@@ -128,7 +128,7 @@ func (s *server) UpdateScenario(ctx context.Context, req *proto.UpdateScenarioRe
|
||||
|
||||
err := s.scenarioService.UpdateScenarioByID(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Name,
|
||||
req.Description,
|
||||
req.Image,
|
||||
@@ -155,7 +155,7 @@ func (s *server) PublicScenario(ctx context.Context, req *proto.PublicScenarioRe
|
||||
|
||||
err := s.scenarioService.UpdateScenarioStatusByID(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
"public",
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin), // публикация = момент отчуждения прав
|
||||
@@ -183,7 +183,7 @@ func (s *server) DraftScenario(ctx context.Context, req *proto.DraftScenarioReq)
|
||||
|
||||
err := s.scenarioService.UpdateScenarioStatusByID(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
"draft",
|
||||
claims.UserID,
|
||||
true,
|
||||
@@ -210,7 +210,7 @@ func (s *server) DeleteScenario(ctx context.Context, req *proto.DeleteScenarioRe
|
||||
// отчуждено); админ может.
|
||||
err := s.scenarioService.DeleteScenarioByID(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
)
|
||||
|
||||
+28
-28
@@ -26,14 +26,14 @@ func (s *server) CreateScreenSession(ctx context.Context, _ *proto.CreateScreenS
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось создать сессию экрана")
|
||||
}
|
||||
return &proto.CreateScreenSessionRsp{ScreenId: fmt.Sprint(id), AccessToken: token}, nil
|
||||
return &proto.CreateScreenSessionRsp{ScreenID: fmt.Sprint(id), AccessToken: token}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetScreenState(ctx context.Context, req *proto.GetScreenStateReq) (*proto.GetScreenStateRsp, error) {
|
||||
if req == nil || req.ScreenId == "" || req.AccessToken == "" {
|
||||
if req == nil || req.ScreenID == "" || req.AccessToken == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректные данные экрана")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
id, err := strconv.Atoi(req.ScreenID)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
@@ -53,13 +53,13 @@ func (s *server) GetGameScreens(ctx context.Context, req *proto.GetGameScreensRe
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 {
|
||||
if req == nil || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameId)); err != nil {
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
sessions, err := s.screenRepo.ListByGame(ctx, int(req.GameId))
|
||||
sessions, err := s.screenRepo.ListByGame(ctx, int(req.GameID))
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить экраны игры")
|
||||
}
|
||||
@@ -76,18 +76,18 @@ func (s *server) BindScreen(ctx context.Context, req *proto.BindScreenReq) (*pro
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.ScreenId == "" || req.AccessToken == "" || req.GameId <= 0 {
|
||||
if req == nil || req.ScreenID == "" || req.AccessToken == "" || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректные данные привязки")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
id, err := strconv.Atoi(req.ScreenID)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
if _, err = s.gameService.GetGame(ctx, int(req.GameId)); err != nil {
|
||||
if _, err = s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
hash := hashScreenToken(req.AccessToken)
|
||||
if err = s.screenRepo.Bind(ctx, id, int(req.GameId), hash); err != nil {
|
||||
if err = s.screenRepo.Bind(ctx, id, int(req.GameID), hash); err != nil {
|
||||
if errors.Is(err, screen_sessions_repo.ErrScreenNotFound) {
|
||||
return nil, status.Error(codes.Unauthenticated, "недействительная сессия экрана")
|
||||
}
|
||||
@@ -106,10 +106,10 @@ func (s *server) UnbindScreen(ctx context.Context, req *proto.UnbindScreenReq) (
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.ScreenId == "" {
|
||||
if req == nil || req.ScreenID == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
id, err := strconv.Atoi(req.ScreenID)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
@@ -126,10 +126,10 @@ func (s *server) SetScreenSound(ctx context.Context, req *proto.SetScreenSoundRe
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.ScreenId == "" {
|
||||
if req == nil || req.ScreenID == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
id, err := strconv.Atoi(req.ScreenID)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func screenState(session *screen_sessions_repo.ScreenSession) *proto.ScreenState
|
||||
}
|
||||
}
|
||||
state := &proto.ScreenState{
|
||||
Id: fmt.Sprint(session.ID),
|
||||
ID: fmt.Sprint(session.ID),
|
||||
Status: "disconnected",
|
||||
SoundEnabled: session.Sound,
|
||||
Mode: proto.ScreenMode(session.Mode),
|
||||
@@ -185,7 +185,7 @@ func screenState(session *screen_sessions_repo.ScreenSession) *proto.ScreenState
|
||||
}
|
||||
if session.GameID != nil {
|
||||
gameID := int32(*session.GameID)
|
||||
state.GameId = &gameID
|
||||
state.GameID = &gameID
|
||||
if state.Mode == proto.ScreenMode_SCREEN_MODE_UNSPECIFIED {
|
||||
state.Mode = proto.ScreenMode_SCREEN_MODE_COVER
|
||||
}
|
||||
@@ -223,13 +223,13 @@ func (s *server) SetScreenMode(ctx context.Context, req *proto.SetScreenModeReq)
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 || req.Mode == proto.ScreenMode_SCREEN_MODE_UNSPECIFIED {
|
||||
if req == nil || req.GameID <= 0 || req.Mode == proto.ScreenMode_SCREEN_MODE_UNSPECIFIED {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный режим экрана")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameId)); err != nil {
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if err := s.screenRepo.SetMode(ctx, int(req.GameId), int32(req.Mode)); err != nil {
|
||||
if err := s.screenRepo.SetMode(ctx, int(req.GameID), int32(req.Mode)); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось изменить режим экранов")
|
||||
}
|
||||
return &proto.SetScreenModeRsp{}, nil
|
||||
@@ -239,7 +239,7 @@ func (s *server) SetScreenTimer(ctx context.Context, req *proto.SetScreenTimerRe
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 || req.DurationSeconds <= 0 || req.DurationSeconds > 24*60*60 {
|
||||
if req == nil || req.GameID <= 0 || req.DurationSeconds <= 0 || req.DurationSeconds > 24*60*60 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректные параметры таймера")
|
||||
}
|
||||
label := strings.TrimSpace(req.Label)
|
||||
@@ -249,10 +249,10 @@ func (s *server) SetScreenTimer(ctx context.Context, req *proto.SetScreenTimerRe
|
||||
if len(label) > 200 {
|
||||
return nil, status.Error(codes.InvalidArgument, "слишком длинная надпись таймера")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameId)); err != nil {
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if err := s.screenRepo.SetTimer(ctx, int(req.GameId), req.DurationSeconds, label); err != nil {
|
||||
if err := s.screenRepo.SetTimer(ctx, int(req.GameID), req.DurationSeconds, label); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось настроить таймер экранов")
|
||||
}
|
||||
return &proto.SetScreenTimerRsp{}, nil
|
||||
@@ -262,14 +262,14 @@ func (s *server) SendScreenCommand(ctx context.Context, req *proto.SendScreenCom
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 || req.Command == proto.ScreenCommand_SCREEN_COMMAND_UNSPECIFIED {
|
||||
if req == nil || req.GameID <= 0 || req.Command == proto.ScreenCommand_SCREEN_COMMAND_UNSPECIFIED {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректная команда экрана")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameId)); err != nil {
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if isTimerCommand(req.Command) {
|
||||
if err := s.screenRepo.SetTimerCommand(ctx, int(req.GameId), int32(req.Command)); err != nil {
|
||||
if err := s.screenRepo.SetTimerCommand(ctx, int(req.GameID), int32(req.Command)); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось выполнить команду таймера")
|
||||
}
|
||||
return &proto.SendScreenCommandRsp{}, nil
|
||||
@@ -280,7 +280,7 @@ func (s *server) SendScreenCommand(ctx context.Context, req *proto.SendScreenCom
|
||||
if req.Volume < 0 || req.Volume > 100 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректная громкость")
|
||||
}
|
||||
if err := s.screenRepo.SetCommand(ctx, int(req.GameId), int32(req.Command), req.PositionMs, req.Volume); err != nil {
|
||||
if err := s.screenRepo.SetCommand(ctx, int(req.GameID), int32(req.Command), req.PositionMs, req.Volume); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить позицию экранов")
|
||||
}
|
||||
return &proto.SendScreenCommandRsp{}, nil
|
||||
@@ -291,10 +291,10 @@ func isTimerCommand(command proto.ScreenCommand) bool {
|
||||
}
|
||||
|
||||
func (s *server) GetScreenResults(ctx context.Context, req *proto.GetScreenResultsReq) (*proto.GetScreenResultsRsp, error) {
|
||||
if req == nil || req.ScreenId == "" || req.AccessToken == "" {
|
||||
if req == nil || req.ScreenID == "" || req.AccessToken == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректные данные экрана")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
id, err := strconv.Atoi(req.ScreenID)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func mapScenario(o *scenarios_service.Scenario) *proto.Scenario {
|
||||
publishedAt = timestamppb.New(*o.PublishedAt)
|
||||
}
|
||||
return &proto.Scenario{
|
||||
Id: int32(o.ID),
|
||||
ID: int32(o.ID),
|
||||
Name: o.Name,
|
||||
Description: o.Description,
|
||||
Image: o.Image,
|
||||
|
||||
@@ -9,7 +9,7 @@ func mapTeam(
|
||||
o *game_model.Team,
|
||||
) *proto.Team {
|
||||
return &proto.Team{
|
||||
Id: int32(o.ID),
|
||||
ID: int32(o.ID),
|
||||
Name: o.Name,
|
||||
Status: o.Status,
|
||||
Password: o.Password,
|
||||
|
||||
@@ -26,10 +26,10 @@ func (s *server) DownloadTeamQR(ctx context.Context, req *proto.GetGameReq) (*ht
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.Id <= 0 {
|
||||
if req == nil || req.ID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
data, filename, err := s.teamService.DownloadTeamQR(ctx, int(req.Id))
|
||||
data, filename, err := s.teamService.DownloadTeamQR(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, games_repo.ErrGameNotFound):
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestDownloadTeamQRAccess(t *testing.T) {
|
||||
{ctxWithClaims("author"), -1, codes.InvalidArgument},
|
||||
{ctxWithClaims("admin"), 0, codes.InvalidArgument},
|
||||
} {
|
||||
_, err := s.DownloadTeamQR(tc.ctx, &proto.GetGameReq{Id: tc.id})
|
||||
_, err := s.DownloadTeamQR(tc.ctx, &proto.GetGameReq{ID: tc.id})
|
||||
if status.Code(err) != tc.want {
|
||||
t.Errorf("code = %v, want %v", status.Code(err), tc.want)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (s *server) AddTeam(ctx context.Context, req *proto.AddTeamReq) (*proto.Add
|
||||
team, err := s.teamService.AddTeam(
|
||||
ctx,
|
||||
claims.UserID,
|
||||
int(req.GameId),
|
||||
int(req.GameID),
|
||||
req.Name,
|
||||
req.CaptainEmail,
|
||||
)
|
||||
@@ -33,7 +33,7 @@ func (s *server) AddTeam(ctx context.Context, req *proto.AddTeamReq) (*proto.Add
|
||||
}
|
||||
|
||||
return &proto.AddTeamRsp{
|
||||
Id: int32(team.ID),
|
||||
ID: int32(team.ID),
|
||||
Password: team.Password,
|
||||
}, nil
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func (s *server) UpdateTeam(ctx context.Context, req *proto.UpdateTeamReq) (*pro
|
||||
|
||||
err := s.teamService.UpdateTeam(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Name,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -72,7 +72,7 @@ func (s *server) DeleteTeam(ctx context.Context, req *proto.DeleteTeamReq) (*pro
|
||||
|
||||
err := s.teamService.DeleteTeam(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteTeamRsp{
|
||||
@@ -94,7 +94,7 @@ func (s *server) GiveTeamApplications(ctx context.Context, req *proto.GiveTeamAp
|
||||
|
||||
err := s.gameplayService.GiveTeamApplications(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Name,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -109,7 +109,7 @@ func (s *server) GiveTeamApplications(ctx context.Context, req *proto.GiveTeamAp
|
||||
func (s *server) GetTeamStory(ctx context.Context, req *proto.GetTeamStoryReq) (*proto.GetTeamStoryRsp, error) {
|
||||
story, game, actions, err := s.gameplayService.GetTeamActions(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Password,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -132,7 +132,7 @@ func (s *server) GetTeamStory(ctx context.Context, req *proto.GetTeamStoryReq) (
|
||||
func (s *server) AddTeamAction(ctx context.Context, req *proto.AddTeamActionReq) (*proto.AddTeamActionRsp, error) {
|
||||
err := s.gameplayService.AddTeamAction(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
req.Password,
|
||||
req.Code,
|
||||
false,
|
||||
@@ -157,7 +157,7 @@ func (s *server) DeleteLastTeamAction(ctx context.Context, req *proto.DeleteLast
|
||||
|
||||
err := s.gameplayService.DeleteLastTeamAction(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
int(req.ID),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteLastTeamActionRsp{
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s *server) GetTicket(ctx context.Context, req *proto.GetTicketReq) (*proto
|
||||
}
|
||||
|
||||
result := &proto.TicketPage{
|
||||
Id: int32(page.ID),
|
||||
ID: int32(page.ID),
|
||||
GameName: page.GameName,
|
||||
StartAt: timestamppb.New(page.StartAt),
|
||||
Status: page.Status,
|
||||
@@ -55,7 +55,7 @@ func (s *server) AcceptTicket(ctx context.Context, req *proto.AcceptTicketReq) (
|
||||
if err != nil {
|
||||
return &proto.AcceptTicketRsp{Error: err.Error()}, nil
|
||||
}
|
||||
result := &proto.TicketPage{Id: int32(page.ID), GameName: page.GameName, StartAt: timestamppb.New(page.StartAt), Status: page.Status, GameStatus: page.GameStatus}
|
||||
result := &proto.TicketPage{ID: int32(page.ID), GameName: page.GameName, StartAt: timestamppb.New(page.StartAt), Status: page.Status, GameStatus: page.GameStatus}
|
||||
if page.Location != nil {
|
||||
result.Location = *page.Location
|
||||
}
|
||||
@@ -76,18 +76,18 @@ func (s *server) IssueGameTickets(ctx context.Context, req *proto.IssueGameTicke
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 {
|
||||
if req == nil || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
|
||||
tickets, err := s.ticketService.Issue(ctx, int(req.GameId), int(req.Count))
|
||||
tickets, err := s.ticketService.Issue(ctx, int(req.GameID), int(req.Count))
|
||||
if err != nil {
|
||||
return &proto.IssueGameTicketsRsp{Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
result := make([]*proto.Ticket, 0, len(tickets))
|
||||
for _, ticket := range tickets {
|
||||
result = append(result, &proto.Ticket{Id: int32(ticket.ID), Url: ticket.URL})
|
||||
result = append(result, &proto.Ticket{ID: int32(ticket.ID), URL: ticket.URL})
|
||||
}
|
||||
return &proto.IssueGameTicketsRsp{Tickets: result}, nil
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func mapUser(o *repos.User) *proto.User {
|
||||
return nil
|
||||
}
|
||||
return &proto.User{
|
||||
Id: int32(o.ID),
|
||||
ID: int32(o.ID),
|
||||
Username: o.Username,
|
||||
Email: o.Email,
|
||||
Roles: o.Roles,
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestMapUser(t *testing.T) {
|
||||
if got == nil {
|
||||
t.Fatal("mapUser вернул nil для не-nil пользователя")
|
||||
}
|
||||
if got.Id != 42 || got.Username != "detective" || got.Email != "d@example.com" {
|
||||
if got.ID != 42 || got.Username != "detective" || got.Email != "d@example.com" {
|
||||
t.Errorf("неожиданный маппинг: %+v", got)
|
||||
}
|
||||
if len(got.Roles) != 1 || got.Roles[0] != "user" {
|
||||
|
||||
@@ -175,15 +175,15 @@ func (s *server) GetUsers(ctx context.Context, req *proto.GetUsersReq) (*proto.G
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetUserById(ctx context.Context, req *proto.GetUserByIdReq) (*proto.GetUserByIdRsp, error) {
|
||||
user, err := s.usersService.GetUserByID(ctx, int(req.Id))
|
||||
func (s *server) GetUserByID(ctx context.Context, req *proto.GetUserByIDReq) (*proto.GetUserByIDRsp, error) {
|
||||
user, err := s.usersService.GetUserByID(ctx, int(req.ID))
|
||||
if err != nil {
|
||||
return &proto.GetUserByIdRsp{
|
||||
return &proto.GetUserByIDRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.GetUserByIdRsp{
|
||||
return &proto.GetUserByIDRsp{
|
||||
User: mapUser(user),
|
||||
}, nil
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func (s *server) AddUserRole(ctx context.Context, req *proto.AddUserRoleReq) (*p
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if err := s.usersService.AddUserRole(ctx, int(req.Id), req.Role); err != nil {
|
||||
if err := s.usersService.AddUserRole(ctx, int(req.ID), req.Role); err != nil {
|
||||
return &proto.AddUserRoleRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
@@ -229,7 +229,7 @@ func (s *server) DeleteUserRole(ctx context.Context, req *proto.DeleteUserRoleRe
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if err := s.usersService.DeleteUserRole(ctx, int(req.Id), req.Role); err != nil {
|
||||
if err := s.usersService.DeleteUserRole(ctx, int(req.ID), req.Role); err != nil {
|
||||
return &proto.DeleteUserRoleRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
@@ -256,7 +256,7 @@ func (s *server) ChangeUserPassword(ctx context.Context, req *proto.ChangeUserPa
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Error(codes.PermissionDenied, "Недостаточно прав")
|
||||
}
|
||||
err := s.usersService.ChangeUserPassword(ctx, claims.UserID, int(req.GetId()), req.GetNewPassword())
|
||||
err := s.usersService.ChangeUserPassword(ctx, claims.UserID, int(req.GetID()), req.GetNewPassword())
|
||||
switch {
|
||||
case errors.Is(err, users_service.ErrPasswordChangeForbidden):
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
|
||||
+495
-488
File diff suppressed because it is too large
Load Diff
+628
-628
File diff suppressed because it is too large
Load Diff
+21
-15
@@ -4,6 +4,12 @@
|
||||
// - protoc v7.36.0
|
||||
// source: main.proto
|
||||
|
||||
// Contract rules:
|
||||
// - fields inside each message are declared in ascending number order;
|
||||
// - published field numbers are never renumbered or reused;
|
||||
// - use ID, <name>ID and URL for abbreviation fields so generated clients
|
||||
// keep the same naming convention across Go and TypeScript.
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
@@ -33,7 +39,7 @@ const (
|
||||
EveningDetectiveServer_GetPrivacy_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetPrivacy"
|
||||
EveningDetectiveServer_GetConsent_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetConsent"
|
||||
EveningDetectiveServer_GetUsers_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetUsers"
|
||||
EveningDetectiveServer_GetUserById_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetUserById"
|
||||
EveningDetectiveServer_GetUserByID_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetUserByID"
|
||||
EveningDetectiveServer_GetMe_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/GetMe"
|
||||
EveningDetectiveServer_ChangeUserPassword_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/ChangeUserPassword"
|
||||
EveningDetectiveServer_AddUserRole_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/AddUserRole"
|
||||
@@ -124,7 +130,7 @@ type EveningDetectiveServerClient interface {
|
||||
GetPrivacy(ctx context.Context, in *GetPrivacyReq, opts ...grpc.CallOption) (*GetPrivacyRsp, error)
|
||||
GetConsent(ctx context.Context, in *GetConsentReq, opts ...grpc.CallOption) (*GetConsentRsp, error)
|
||||
GetUsers(ctx context.Context, in *GetUsersReq, opts ...grpc.CallOption) (*GetUsersRsp, error)
|
||||
GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdRsp, error)
|
||||
GetUserByID(ctx context.Context, in *GetUserByIDReq, opts ...grpc.CallOption) (*GetUserByIDRsp, error)
|
||||
GetMe(ctx context.Context, in *GetMeReq, opts ...grpc.CallOption) (*GetMeRsp, error)
|
||||
// Только администратор; сеансы пользователя сохраняются.
|
||||
// Ошибки: 401, 403, 400, 404, 500.
|
||||
@@ -346,10 +352,10 @@ func (c *eveningDetectiveServerClient) GetUsers(ctx context.Context, in *GetUser
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *eveningDetectiveServerClient) GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdRsp, error) {
|
||||
func (c *eveningDetectiveServerClient) GetUserByID(ctx context.Context, in *GetUserByIDReq, opts ...grpc.CallOption) (*GetUserByIDRsp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUserByIdRsp)
|
||||
err := c.cc.Invoke(ctx, EveningDetectiveServer_GetUserById_FullMethodName, in, out, cOpts...)
|
||||
out := new(GetUserByIDRsp)
|
||||
err := c.cc.Invoke(ctx, EveningDetectiveServer_GetUserByID_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1083,7 +1089,7 @@ type EveningDetectiveServerServer interface {
|
||||
GetPrivacy(context.Context, *GetPrivacyReq) (*GetPrivacyRsp, error)
|
||||
GetConsent(context.Context, *GetConsentReq) (*GetConsentRsp, error)
|
||||
GetUsers(context.Context, *GetUsersReq) (*GetUsersRsp, error)
|
||||
GetUserById(context.Context, *GetUserByIdReq) (*GetUserByIdRsp, error)
|
||||
GetUserByID(context.Context, *GetUserByIDReq) (*GetUserByIDRsp, error)
|
||||
GetMe(context.Context, *GetMeReq) (*GetMeRsp, error)
|
||||
// Только администратор; сеансы пользователя сохраняются.
|
||||
// Ошибки: 401, 403, 400, 404, 500.
|
||||
@@ -1214,8 +1220,8 @@ func (UnimplementedEveningDetectiveServerServer) GetConsent(context.Context, *Ge
|
||||
func (UnimplementedEveningDetectiveServerServer) GetUsers(context.Context, *GetUsersReq) (*GetUsersRsp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUsers not implemented")
|
||||
}
|
||||
func (UnimplementedEveningDetectiveServerServer) GetUserById(context.Context, *GetUserByIdReq) (*GetUserByIdRsp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUserById not implemented")
|
||||
func (UnimplementedEveningDetectiveServerServer) GetUserByID(context.Context, *GetUserByIDReq) (*GetUserByIDRsp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUserByID not implemented")
|
||||
}
|
||||
func (UnimplementedEveningDetectiveServerServer) GetMe(context.Context, *GetMeReq) (*GetMeRsp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetMe not implemented")
|
||||
@@ -1686,20 +1692,20 @@ func _EveningDetectiveServer_GetUsers_Handler(srv interface{}, ctx context.Conte
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EveningDetectiveServer_GetUserById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserByIdReq)
|
||||
func _EveningDetectiveServer_GetUserByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserByIDReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(EveningDetectiveServerServer).GetUserById(ctx, in)
|
||||
return srv.(EveningDetectiveServerServer).GetUserByID(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: EveningDetectiveServer_GetUserById_FullMethodName,
|
||||
FullMethod: EveningDetectiveServer_GetUserByID_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EveningDetectiveServerServer).GetUserById(ctx, req.(*GetUserByIdReq))
|
||||
return srv.(EveningDetectiveServerServer).GetUserByID(ctx, req.(*GetUserByIDReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
@@ -3042,8 +3048,8 @@ var EveningDetectiveServer_ServiceDesc = grpc.ServiceDesc{
|
||||
Handler: _EveningDetectiveServer_GetUsers_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserById",
|
||||
Handler: _EveningDetectiveServer_GetUserById_Handler,
|
||||
MethodName: "GetUserByID",
|
||||
Handler: _EveningDetectiveServer_GetUserByID_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetMe",
|
||||
|
||||
Reference in New Issue
Block a user