From 7cb9fcd414ab5a3789f57dd835996d0df23df23c Mon Sep 17 00:00:00 2001 From: Marcin Bator Date: Tue, 29 Oct 2024 21:52:25 +0100 Subject: [PATCH] fix: #dev gameRecord requirements --- .../Module/GameRecord/GameRecordController.cs | 2 +- .../Infrastructure/Module/GameRecord/GameRecordService.cs | 6 ++++-- rag-2-backend/Infrastructure/Module/Stats/StatsService.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordController.cs b/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordController.cs index df1f9b7..62d5b7c 100644 --- a/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordController.cs +++ b/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordController.cs @@ -41,7 +41,7 @@ public FileContentResult DownloadRecordData([Required] int recordedGameId) /// Add game recording, limits are present (Auth) /// User or game not found - /// Space limit exceeded + /// Space limit exceeded or values state cannot be empty [HttpPost] [Authorize] public void AddGameRecord([FromBody] [Required] RecordedGameRequest request) diff --git a/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordService.cs b/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordService.cs index 8aef08d..aa5fdce 100644 --- a/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordService.cs +++ b/rag-2-backend/Infrastructure/Module/GameRecord/GameRecordService.cs @@ -42,8 +42,10 @@ public byte[] DownloadRecordData(int recordedGameId, string email) public void AddGameRecord(RecordedGameRequest request, string email) { - var user = userDao.GetUserByEmailOrThrow(email); + if (request.Values.Count == 0 || request.Values[^1].State == null) + throw new BadRequestException("Value state cannot be empty"); + var user = userDao.GetUserByEmailOrThrow(email); if (GetSizeByUser(user.Id, request.Values.Count) > configuration.GetValue("UserDataLimitMb")) throw new BadRequestException("Space limit exceeded"); @@ -56,7 +58,7 @@ public void AddGameRecord(RecordedGameRequest request, string email) Values = request.Values, User = user, Players = request.Values[0].Players, - OutputSpec = request.Values[0].OutputSpec, + OutputSpec = request.Values[0].OutputSpec ?? "", EndState = request.Values[^1].State?.ToString() }; diff --git a/rag-2-backend/Infrastructure/Module/Stats/StatsService.cs b/rag-2-backend/Infrastructure/Module/Stats/StatsService.cs index 24fdfd7..a93d700 100644 --- a/rag-2-backend/Infrastructure/Module/Stats/StatsService.cs +++ b/rag-2-backend/Infrastructure/Module/Stats/StatsService.cs @@ -21,7 +21,7 @@ public UserStatsResponse GetStatsForUser(string email, int userId) { var principal = _context.Users.FirstOrDefault(u => u.Email == email) ?? throw new NotFoundException("User not found"); - + var user = _context.Users.FirstOrDefault(u => u.Id == userId) ?? throw new NotFoundException("User not found");