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

@@ -10,7 +10,7 @@
<div class="container">
<div class="input-game">
<div id="first-label" class="label">@ResourcesKey.Title :</div>
<InputText class="title" @bind-Value=GameDto.Title />
<InputText class="title" @bind-Value=GameDto.Title/>
</div>
<div class="input-game">
<div class="label">@ResourcesKey.ReleaseDate :</div>

View File

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

View File

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

View File

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