Fetch games
This commit is contained in:
@@ -13,14 +13,6 @@ public class GameBase : ComponentBase
|
|||||||
NavigationManager.NavigateTo($"/Game/Detail/{GameDto.Id}");
|
NavigationManager.NavigateTo($"/Game/Detail/{GameDto.Id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void HandlePlatformClicked(PlatformDto platform)
|
|
||||||
{
|
|
||||||
if (platform.Url != null)
|
|
||||||
{
|
|
||||||
NavigationManager.NavigateTo(platform.Url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected string GetFormatedStorageSpace()
|
protected string GetFormatedStorageSpace()
|
||||||
{
|
{
|
||||||
if (GameDto.StorageSpace == null)
|
if (GameDto.StorageSpace == null)
|
||||||
@@ -28,15 +20,11 @@ public class GameBase : ComponentBase
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quotien = (int)Math.Round((decimal)GameDto.StorageSpace) / 1000;
|
return GameDto.StorageSpace switch
|
||||||
string unit = quotien switch
|
|
||||||
{
|
{
|
||||||
0 => "Mo",
|
> 1000000 => $"{GameDto.StorageSpace / 1000000:f1} To",
|
||||||
1 => "Go",
|
> 1000 => $"{GameDto.StorageSpace / 1000:f1} Go",
|
||||||
2 => "To",
|
_ => $"{GameDto.StorageSpace:f1} Mo"
|
||||||
_ => string.Empty
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return $"{GameDto.StorageSpace % 1000:g1} {unit}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,22 @@
|
|||||||
|
|
||||||
<span class="title">@GameDto.Title</span>
|
<span class="title">@GameDto.Title</span>
|
||||||
|
|
||||||
<span class="release-date">@GameDto.ReleaseDate?.ToShortDateString() ?? @ResourcesKey.Unknown</span>
|
<span class="release-date">@(GameDto.ReleaseDate?.ToShortDateString() ?? @ResourcesKey.Unknown)</span>
|
||||||
|
|
||||||
<div class="platforms">
|
<div class="platforms">
|
||||||
@foreach (var platform in GameDto.Platforms ?? [])
|
@foreach (var platform in GameDto.Platforms ?? [])
|
||||||
{
|
{
|
||||||
<div class="platform-pill pill"
|
<a href="@platform.Url"
|
||||||
@onclick=@(_ => HandlePlatformClicked(platform))>
|
class="pill @(string.IsNullOrEmpty(platform.Url) ? "" : "platform-pill")">
|
||||||
@platform.Label
|
@platform.Label
|
||||||
</div>
|
</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
@foreach (var tag in GameDto.Tags ?? [])
|
@foreach (var tag in GameDto.Tags ?? [])
|
||||||
{
|
{
|
||||||
<div class="tag-pill pill">
|
<div class="pill">
|
||||||
@tag.Label
|
@tag.Label
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,39 @@
|
|||||||
|
.row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 48px 5fr 70px 2fr 3fr 60px 30px 30px;
|
||||||
|
text-wrap: nowrap;
|
||||||
|
height: 64px;
|
||||||
|
background: var(--input-secondary);
|
||||||
|
box-shadow: var(--drop-shadow);
|
||||||
|
border-radius: var(--big-radius);
|
||||||
|
overflow: hidden;
|
||||||
|
align-content: center;
|
||||||
|
align-items:center;
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
width: fit-content;
|
||||||
|
height: 24px;
|
||||||
|
padding: 0 6px;
|
||||||
|
background: rgb(255, 255, 255, 0.2);
|
||||||
|
border-radius: var(--small-radius);
|
||||||
|
align-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.platforms, .tags {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.platform-pill {
|
||||||
|
color: var(--violet);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.platform-pill:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 240px;
|
width: 100%;
|
||||||
border-left: 2px solid var(--line);
|
border-left: 2px solid var(--line);
|
||||||
z-index: var(--index-content);
|
z-index: var(--index-content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,17 +13,21 @@
|
|||||||
|
|
||||||
<GameHeader AddTypeChanged="HandleAddClicked">
|
<GameHeader AddTypeChanged="HandleAddClicked">
|
||||||
<GameFilter Categories="Categories"
|
<GameFilter Categories="Categories"
|
||||||
@bind-DisplayType=DisplayType
|
@bind-DisplayType=DisplayType
|
||||||
@bind-Value=GameFilter/>
|
@bind-Value=GameFilter/>
|
||||||
</GameHeader>
|
</GameHeader>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@foreach (var game in GamesDto)
|
||||||
|
{
|
||||||
|
<GameRow GameDto="game" />
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AdvancedGameFilter @bind-GameFilter=GameFilter Categories="Categories" />
|
<AdvancedGameFilter @bind-GameFilter=GameFilter Categories="Categories" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
||||||
<GameCreationForm Categories="Categories" OnSubmit="HandleFetchCategories" />
|
<GameCreationForm Categories="Categories" OnSubmit="HandleFetchDatas" />
|
||||||
</Popup>
|
</Popup>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using GameIdeas.BlazorApp.Shared.Components.Popup;
|
|||||||
using GameIdeas.BlazorApp.Shared.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||||
|
|
||||||
@@ -13,11 +14,13 @@ public partial class Game
|
|||||||
private DisplayType DisplayType = DisplayType.List;
|
private DisplayType DisplayType = DisplayType.List;
|
||||||
private GameFilterDto GameFilter = new();
|
private GameFilterDto GameFilter = new();
|
||||||
private Popup? ManualAddPopup;
|
private Popup? ManualAddPopup;
|
||||||
|
private bool IsLoading;
|
||||||
private CategoriesDto? Categories;
|
private CategoriesDto? Categories;
|
||||||
|
private IEnumerable<GameDto> GamesDto = [];
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await HandleFetchCategories();
|
await HandleFetchDatas();
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
private void HandleAddClicked(AddType addType)
|
private void HandleAddClicked(AddType addType)
|
||||||
@@ -37,8 +40,22 @@ public partial class Game
|
|||||||
{
|
{
|
||||||
ManualAddPopup?.Close();
|
ManualAddPopup?.Close();
|
||||||
}
|
}
|
||||||
private async Task HandleFetchCategories()
|
private async Task HandleFetchDatas()
|
||||||
{
|
{
|
||||||
Categories = await GameGateway.FetchCategories();
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
Categories = await GameGateway.FetchCategories();
|
||||||
|
GamesDto = await GameGateway.FetchGames(new PaggingDto() { CurrentPage = 1, NumberPerPage = 50 });
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
.container {
|
.container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 240px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
justify-content: space-between;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
z-index: var(--index-content);
|
z-index: var(--index-content);
|
||||||
|
margin: 0 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
}
|
}
|
||||||
@@ -33,4 +33,17 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
|||||||
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories);
|
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(pagging));
|
||||||
|
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ public interface IGameGateway
|
|||||||
{
|
{
|
||||||
Task<CategoriesDto> FetchCategories();
|
Task<CategoriesDto> FetchCategories();
|
||||||
Task<int> CreateGame(GameDto game);
|
Task<int> CreateGame(GameDto game);
|
||||||
|
Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
namespace GameIdeas.BlazorApp.Shared.Constants;
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Shared.Constants;
|
||||||
|
|
||||||
public static class Endpoints
|
public static class Endpoints
|
||||||
{
|
{
|
||||||
public static class Game
|
public static class Game
|
||||||
{
|
{
|
||||||
public static readonly string Create = "api/Game/Create";
|
public static readonly string Create = "api/Game/Create";
|
||||||
|
public static string Fetch(PaggingDto pagging) =>
|
||||||
|
$"api/Game?{nameof(pagging.CurrentPage)}={pagging.CurrentPage}&{nameof(pagging.NumberPerPage)}={pagging.NumberPerPage}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Category
|
public static class Category
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class GameNotFoundException(string message) : Exception(message);
|
||||||
@@ -39,6 +39,7 @@ public class Translations (TranslationService translationService)
|
|||||||
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
|
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
|
||||||
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
||||||
public string Unknown => translationService.Translate(nameof(Unknown));
|
public string Unknown => translationService.Translate(nameof(Unknown));
|
||||||
|
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourcesKey
|
public static class ResourcesKey
|
||||||
@@ -86,4 +87,5 @@ public static class ResourcesKey
|
|||||||
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized.");
|
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized.");
|
||||||
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
||||||
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
||||||
|
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<IEnumerable<GameDto>>> SearchGames([FromQuery] PaggingDto pagging)
|
public async Task<ActionResult<IEnumerable<GameDto>>> GetGames([FromQuery] PaggingDto pagging)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,5 +34,7 @@
|
|||||||
"ErrorCreateGame": "Erreur lors de la Création d'un jeu",
|
"ErrorCreateGame": "Erreur lors de la Création d'un jeu",
|
||||||
"InvalidTitle": "Le titre est incorrect",
|
"InvalidTitle": "Le titre est incorrect",
|
||||||
"InvalidInterest": "L'interêt est incorrect",
|
"InvalidInterest": "L'interêt est incorrect",
|
||||||
"Unknown": "Inconnu"
|
"Unknown": "Inconnu",
|
||||||
|
"ErrorFetchGames": "Erreur lors de la récupération des jeux"
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user