generated from VLADIMIR/template
add results
This commit is contained in:
@@ -357,6 +357,35 @@ func (s *server) SendScreenCommand(ctx context.Context, req *proto.SendScreenCom
|
||||
return &proto.SendScreenCommandRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetScreenResults(ctx context.Context, req *proto.GetScreenResultsReq) (*proto.GetScreenResultsRsp, error) {
|
||||
if req == nil || req.ScreenId == "" || req.AccessToken == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректные данные экрана")
|
||||
}
|
||||
id, err := strconv.Atoi(req.ScreenId)
|
||||
if err != nil || id <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор экрана")
|
||||
}
|
||||
session, err := s.screenRepo.Get(ctx, id, hashScreenToken(req.AccessToken))
|
||||
if errors.Is(err, screen_sessions_repo.ErrScreenNotFound) {
|
||||
return nil, status.Error(codes.Unauthenticated, "недействительная сессия экрана")
|
||||
}
|
||||
if err != nil || session.GameID == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "экран не привязан к игре")
|
||||
}
|
||||
game, err := s.gameService.GetGame(ctx, *session.GameID)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if game.Status != "finish" {
|
||||
return nil, status.Error(codes.FailedPrecondition, "результаты доступны после завершения игры")
|
||||
}
|
||||
results, err := s.gameService.GetGameResults(ctx, *session.GameID)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить результаты")
|
||||
}
|
||||
return &proto.GetScreenResultsRsp{Questions: mapResultsQuestions(results.Questions), Teams: mapTeamResults(results.Teams)}, nil
|
||||
}
|
||||
|
||||
func (s *server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
|
||||
return &proto.PingRsp{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user