|
4 | 4 |
|
5 | 5 | namespace GameOn.Presentation.Controllers.FIFA |
6 | 6 | { |
| 7 | + using GameOn.Application.Common.Players.Queries.GetPlayerByKeycloakId; |
7 | 8 | using GameOn.Application.FIFA.FifaGamePlayed.Commands.CreateFifaGamePlayed; |
| 9 | + using GameOn.Application.FIFA.FifaGamePlayed.Commands.DeclareFifaGamePlayedScore; |
8 | 10 | using GameOn.Application.FIFA.FifaGamePlayed.Commands.DeleteFifaGamePlayed; |
9 | 11 | using GameOn.Application.FIFA.FifaGamePlayed.Commands.UpdateFifaGamePlayed; |
10 | 12 | using GameOn.Application.FIFA.FifaGamePlayed.Queries.GetFifaGamePlayedById; |
@@ -229,5 +231,51 @@ public async Task<IActionResult> Update([FromBody] UpdateGameDto game) |
229 | 231 | return this.Ok(updatedGame); |
230 | 232 | } |
231 | 233 | } |
| 234 | + |
| 235 | + /// <summary> |
| 236 | + /// Declare score in database. |
| 237 | + /// </summary> |
| 238 | + /// <param name="gameId">Game ID.</param> |
| 239 | + /// <param name="score1">Score 1.</param> |
| 240 | + /// <param name="score2">Score 2.</param> |
| 241 | + /// <returns>IActionResult object.</returns> |
| 242 | + [HttpPost] |
| 243 | + [Authorize] |
| 244 | + [Route("{gameId:int}/{score1:int}/{score2:int}")] |
| 245 | + [Produces("application/json")] |
| 246 | + [SwaggerOperation(Summary = "Declares score of a game in database.")] |
| 247 | + [SwaggerResponse(200, "Updated game.", typeof(FifaGamePlayed))] |
| 248 | + [SwaggerResponse(401, "User is not logged in.")] |
| 249 | + [SwaggerResponse(403, "User isn't authorized.")] |
| 250 | + [SwaggerResponse(500, "Unknown error.")] |
| 251 | + public async Task<IActionResult> DeclareScore(int gameId, int score1, int score2) |
| 252 | + { |
| 253 | + var currentUserId = this.User.GetConnectedPlayer().KeycloakId; |
| 254 | + var currentUser = await this.mediator.Send(new GetPlayerByKeycloakIdQuery { KeycloakId = currentUserId }); |
| 255 | + |
| 256 | + if (currentUser is null) |
| 257 | + { |
| 258 | + return this.Problem(); |
| 259 | + } |
| 260 | + |
| 261 | + var updatedGame = await this.mediator.Send(new DeclareFifaGamePlayedScoreCommand { |
| 262 | + ScoreDto = new DeclareScoreDto |
| 263 | + { |
| 264 | + GameId = gameId, |
| 265 | + ScoreTeam1 = score1, |
| 266 | + ScoreTeam2 = score2, |
| 267 | + CurrentPlayerId = currentUser.Id, |
| 268 | + }, |
| 269 | + }); |
| 270 | + |
| 271 | + if (updatedGame is null) |
| 272 | + { |
| 273 | + return this.Problem(); |
| 274 | + } |
| 275 | + else |
| 276 | + { |
| 277 | + return this.Ok(updatedGame); |
| 278 | + } |
| 279 | + } |
232 | 280 | } |
233 | 281 | } |
0 commit comments