Create game
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 46s

This commit is contained in:
Maxime Adler
2025-04-15 11:57:28 +02:00
parent ab0ab54f61
commit ad05e210c2
8 changed files with 45 additions and 16 deletions

View File

@@ -0,0 +1,12 @@
using GameIdeas.Shared.Dto;
namespace GameIdeas.BlazorApp.Helpers;
public static class GameHelper
{
public static void WriteTrackingDto(GameDto game)
{
game.CreationUserId = 100000;
game.CreationDate = DateTime.Now;
}
}

View File

@@ -1,3 +1,4 @@
using GameIdeas.BlazorApp.Helpers;
using GameIdeas.BlazorApp.Pages.Games.Gateways; using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Components.Popup; using GameIdeas.BlazorApp.Shared.Components.Popup;
using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.BlazorApp.Shared.Components.Select.Models;
@@ -20,7 +21,7 @@ public partial class GameCreationForm
private EditContext? EditContext; private EditContext? EditContext;
private readonly SelectTheme Theme = SelectTheme.Creation; private readonly SelectTheme Theme = SelectTheme.Creation;
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 }; private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
private bool IsLoading = true; private bool IsLoading = false;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
@@ -46,10 +47,25 @@ public partial class GameCreationForm
return; return;
} }
try
{
IsLoading = true; IsLoading = true;
await GameGateway.CreateGame(GameDto); GameHelper.WriteTrackingDto(GameDto);
var gameId = await GameGateway.CreateGame(GameDto);
if (gameId != 0)
{
Popup?.Close();
}
}
catch (Exception)
{
throw;
}
finally
{
IsLoading = false; IsLoading = false;
} }
} }
}

View File

@@ -8,13 +8,11 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
public class GameGateway(IHttpClientService httpClientService) : IGameGateway public class GameGateway(IHttpClientService httpClientService) : IGameGateway
{ {
public async Task<GameDto> CreateGame(GameDto game) public async Task<int> CreateGame(GameDto game)
{ {
try try
{ {
var result = await httpClientService.PostAsync<GameDto>(Endpoints.Game.Create, game); return await httpClientService.PostAsync<int>(Endpoints.Game.Create, game);
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame);
} }
catch (Exception) catch (Exception)
{ {

View File

@@ -5,5 +5,5 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
public interface IGameGateway public interface IGameGateway
{ {
Task<CategoriesDto> FetchCategories(); Task<CategoriesDto> FetchCategories();
Task<GameDto> CreateGame(GameDto game); Task<int> CreateGame(GameDto game);
} }

View File

@@ -6,10 +6,10 @@
height: 20px; height: 20px;
align-items: center; align-items: center;
padding: 2px 6px; padding: 2px 6px;
cursor: pointer;
} }
.select-element:hover { .select-element:hover {
cursor: pointer;
background: var(--input-selected); background: var(--input-selected);
} }

View File

@@ -3,7 +3,8 @@
} }
.button { .button {
z-index: var(--index-component) z-index: var(--index-component);
cursor: pointer;
} }
.dropdown { .dropdown {

View File

@@ -40,11 +40,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
} }
[HttpPost("Create")] [HttpPost("Create")]
public async Task<ActionResult<GameDto>> CreateGame([FromBody] GameDto game) public async Task<ActionResult<int>> CreateGame([FromBody] GameDto game)
{ {
try try
{ {
return Created("/Create", await gameService.CreateGame(game)); var gameResult = await gameService.CreateGame(game);
return Created("/Create", gameResult.Id);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -54,11 +55,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
} }
[HttpPut("Update")] [HttpPut("Update")]
public async Task<ActionResult<GameDto>> UpdateGame([FromBody] GameDto game) public async Task<ActionResult<int>> UpdateGame([FromBody] GameDto game)
{ {
try try
{ {
return Created($"/Update", await gameService.UpdateGame(game)); var gameResult = await gameService.UpdateGame(game);
return Created($"/Update", gameResult.Id);
} }
catch (Exception e) catch (Exception e)
{ {