Delete game
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 43s

This commit is contained in:
Maxime Adler
2025-05-12 13:08:23 +02:00
parent bb42aa6dc1
commit 14dc1928bc
11 changed files with 144 additions and 73 deletions

View File

@@ -1,10 +1,10 @@
using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Components;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Pages.Detail;
public partial class GameDetail
public partial class GameDetail : GameBaseComponent
{
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Parameter] public int GameId { get; set; }

View File

@@ -29,7 +29,7 @@ public class GameBase : ComponentBase
switch (option)
{
case DetailOptions.Detail:
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
NavigationManager.NavigateTo($"/Detail/{GameDto.Id}");
break;
case DetailOptions.Edit:
await OnEdit.InvokeAsync(GameDto);

View File

@@ -5,6 +5,7 @@
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
@using GameIdeas.BlazorApp.Shared.Components.Header
@using GameIdeas.BlazorApp.Shared.Components.Popup
@using GameIdeas.BlazorApp.Shared.Components.Popup.Components
@using GameIdeas.Resources
@inherits GameBaseComponent
@layout MainLayout
@@ -24,7 +25,7 @@
{
@foreach (var game in GamesDto)
{
<GameRow GameDto="game" />
<GameRow GameDto="game" OnDelete="HandleDeleteGame" OnEdit="HandleEditGame" />
}
}
else
@@ -43,3 +44,7 @@
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
</Popup>
<Popup @ref=DeletePopup Closable=false>
<ConfirmDelete OnCancel="HandleCancelPopupClicked" OnConfirm="HandleRemoveGame" />
</Popup>

View File

@@ -1,5 +1,6 @@
using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.BlazorApp.Shared.Components;
using GameIdeas.BlazorApp.Shared.Components.Popup;
using GameIdeas.BlazorApp.Shared.Models;
using GameIdeas.Shared.Dto;
using GameIdeas.Shared.Enum;
@@ -12,6 +13,8 @@ public partial class Games : GameBaseComponent
private GameFilterParams GameFilter = new();
private IEnumerable<GameDto> GamesDto = [];
private int CurrentPage;
private Popup? DeletePopup;
private GameDto? GameToDelete;
protected override async Task OnInitializedAsync()
{
@@ -48,4 +51,46 @@ public partial class Games : GameBaseComponent
GameFilter = args;
await HandleFetchDatas(false);
}
private void HandleDeleteGame(GameDto args)
{
DeletePopup?.Open();
GameToDelete = args;
}
private void HandleCancelPopupClicked()
{
DeletePopup?.Close();
GameToDelete = null;
}
private Task HandleEditGame(GameDto args)
{
throw new NotImplementedException();
}
private async Task HandleRemoveGame()
{
DeletePopup?.Close();
if (GameToDelete?.Id == null)
{
return;
}
try
{
IsLoading = true;
await GameGateway.DeleteGame(GameToDelete?.Id ?? 0);
await HandleFetchDatas(false);
}
catch (Exception)
{
throw;
}
GameToDelete = null;
}
}

View File

@@ -76,4 +76,16 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
}
}
public async Task<bool> DeleteGame(int gameIdToDelete)
{
try
{
return await httpClientService.DeleteAsync<bool>(Endpoints.Game.Delete(gameIdToDelete));
}
catch (Exception)
{
throw new GameDeletionException(ResourcesKey.ErrorDeleteGame);
}
}
}

View File

@@ -9,4 +9,5 @@ public interface IGameGateway
Task<int> CreateGame(GameDetailDto game);
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
Task<GameDetailDto> GetGameById(int gameId);
Task<bool> DeleteGame(int gameIdToDelete);
}