feature/apply-filter (#18)
Co-authored-by: Maxime Adler <madler@sqli.com> Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
@@ -4,7 +4,7 @@ namespace GameIdeas.BlazorApp.Helpers;
|
|||||||
|
|
||||||
public static class GameHelper
|
public static class GameHelper
|
||||||
{
|
{
|
||||||
public static void WriteTrackingDto(GameDto game)
|
public static void WriteTrackingDto(GameDetailDto game)
|
||||||
{
|
{
|
||||||
game.CreationUserId = 100000;
|
game.CreationUserId = 100000;
|
||||||
game.CreationDate = DateTime.Now;
|
game.CreationDate = DateTime.Now;
|
||||||
@@ -22,4 +22,19 @@ public static class GameHelper
|
|||||||
_ => "--yellow",
|
_ => "--yellow",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetFormatedStorageSpace(double? storageValue)
|
||||||
|
{
|
||||||
|
if (storageValue == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return storageValue switch
|
||||||
|
{
|
||||||
|
>= 1000000 => $"{storageValue / 1000000:f1} To",
|
||||||
|
>= 1000 => $"{storageValue / 1000:f1} Go",
|
||||||
|
_ => $"{storageValue:f1} Mo"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Helpers;
|
||||||
|
|
||||||
|
public static class UrlHelper
|
||||||
|
{
|
||||||
|
public static string BuildUrlParams(object? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
var properties = model.GetType().GetProperties();
|
||||||
|
var queryParams = properties
|
||||||
|
.Select(p =>
|
||||||
|
{
|
||||||
|
var value = p.GetValue(model);
|
||||||
|
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
return null;
|
||||||
|
case DateTime dateTime:
|
||||||
|
return $"{p.Name}={Uri.EscapeDataString(dateTime.ToString("yyyy-MM-dd HH:mm:ss"))}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value is IEnumerable enumerable and not string)
|
||||||
|
{
|
||||||
|
var items = enumerable.Cast<object>()
|
||||||
|
.Select(item => $"{p.Name}={Uri.EscapeDataString(item?.ToString() ?? string.Empty)}");
|
||||||
|
return string.Join("&", items);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{p.Name}={Uri.EscapeDataString(value.ToString() ?? string.Empty)}";
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
return string.Join("&", queryParams.Where(p => p != null));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,19 +12,4 @@ public class GameBase : ComponentBase
|
|||||||
{
|
{
|
||||||
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
|
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string GetFormatedStorageSpace()
|
|
||||||
{
|
|
||||||
if (GameDto.StorageSpace == null)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GameDto.StorageSpace switch
|
|
||||||
{
|
|
||||||
>= 1000000 => $"{GameDto.StorageSpace / 1000000:f1} To",
|
|
||||||
>= 1000 => $"{GameDto.StorageSpace / 1000:f1} Go",
|
|
||||||
_ => $"{GameDto.StorageSpace:f1} Mo"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public partial class GameCreationForm
|
|||||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||||
[Parameter] public EventCallback OnSubmit { get; set; }
|
[Parameter] public EventCallback OnSubmit { get; set; }
|
||||||
|
|
||||||
private GameDto GameDto = new();
|
private GameDetailDto GameDto = new();
|
||||||
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 };
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="storage">@GetFormatedStorageSpace()</span>
|
<span class="storage">@GameHelper.GetFormatedStorageSpace(GameDto.StorageSpace)</span>
|
||||||
|
|
||||||
<div class="interest">
|
<div class="interest">
|
||||||
<span class="value" style="@($"color: var({GameHelper.GetInterestColor(GameDto.Interest, 5)})")">
|
<span class="value" style="@($"color: var({GameHelper.GetInterestColor(GameDto.Interest, 5)})")">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using GameIdeas.Shared.Dto;
|
|||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||||
|
|
||||||
public class GameValidation : AbstractValidator<GameDto>
|
public class GameValidation : AbstractValidator<GameDetailDto>
|
||||||
{
|
{
|
||||||
public GameValidation()
|
public GameValidation()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,5 +22,11 @@
|
|||||||
<SelectSearch TItem="PublisherDto" Placeholder="@ResourcesKey.Publishers" GetLabel="@(p => p.Name)"
|
<SelectSearch TItem="PublisherDto" Placeholder="@ResourcesKey.Publishers" GetLabel="@(p => p.Name)"
|
||||||
@bind-Values=GameFilter.Publishers @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.Publishers" />
|
@bind-Values=GameFilter.Publishers @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.Publishers" />
|
||||||
|
|
||||||
|
<SelectSearch TItem="int" Placeholder="@ResourcesKey.ReleaseDate" GetLabel="@(p => p.ToString())"
|
||||||
|
@bind-Values=GameFilter.ReleaseYears @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.ReleaseYears" />
|
||||||
|
|
||||||
|
<SelectSearch TItem="int" Placeholder="@ResourcesKey.StorageSize" GetLabel="@GetStorageSpaceLabel"
|
||||||
|
@bind-Values=GameFilter.StorageSpaceIds @bind-Values:after=HandleValueChanged Theme="Theme" Items="@(Categories?.StorageSpaces?.Select(stor => stor.Id).ToList())" />
|
||||||
|
|
||||||
<span class="title">@ResourcesKey.LastAdd</span>
|
<span class="title">@ResourcesKey.LastAdd</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
using GameIdeas.BlazorApp.Helpers;
|
||||||
|
using GameIdeas.BlazorApp.Pages.Games.Header;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
@@ -6,9 +9,9 @@ namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
|||||||
|
|
||||||
public partial class AdvancedGameFilter
|
public partial class AdvancedGameFilter
|
||||||
{
|
{
|
||||||
[Parameter] public GameFilterDto GameFilter { get; set; } = new();
|
[Parameter] public GameFilterParams GameFilter { get; set; } = new();
|
||||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||||
[Parameter] public EventCallback<GameFilterDto> GameFilterChanged { get; set; }
|
[Parameter] public EventCallback<GameFilterParams> GameFilterChanged { get; set; }
|
||||||
|
|
||||||
private readonly SelectTheme Theme = SelectTheme.AdvancedFilter;
|
private readonly SelectTheme Theme = SelectTheme.AdvancedFilter;
|
||||||
|
|
||||||
@@ -16,4 +19,31 @@ public partial class AdvancedGameFilter
|
|||||||
{
|
{
|
||||||
await GameFilterChanged.InvokeAsync(GameFilter);
|
await GameFilterChanged.InvokeAsync(GameFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetStorageSpaceLabel(int storageSpaceId)
|
||||||
|
{
|
||||||
|
var storageSpace = Categories?.StorageSpaces?.FirstOrDefault(c => c.Id == storageSpaceId)
|
||||||
|
?? throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
|
||||||
|
|
||||||
|
if (storageSpace.MinSize == null && storageSpace.MaxSize != null)
|
||||||
|
{
|
||||||
|
return string.Format(ResourcesKey.MinStorageSpaceFormat,
|
||||||
|
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storageSpace.MinSize != null && storageSpace.MaxSize == null)
|
||||||
|
{
|
||||||
|
return string.Format(ResourcesKey.MaxStorageSpaceFormat,
|
||||||
|
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storageSpace.MinSize != null && storageSpace.MaxSize != null)
|
||||||
|
{
|
||||||
|
return string.Format(ResourcesKey.MinMaxStorageSpaceFormat,
|
||||||
|
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize),
|
||||||
|
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
@using GameIdeas.Shared.Dto
|
@using GameIdeas.Shared.Dto
|
||||||
|
|
||||||
<div class="form-filter">
|
<div class="form-filter">
|
||||||
<Select TItem="SortPropertyDto" ValuesChanged=HandleSortPropertyClicked
|
<Select TItem="SortPropertyDto" Values="[Value.SortProperty]" ValuesChanged=HandleSortPropertyClicked
|
||||||
THeader="SortTypeDto" HeaderValuesChanged=HandleSortTypeClicked
|
THeader="SortTypeDto" HeaderValues="[Value.SortType]" HeaderValuesChanged=HandleSortTypeClicked
|
||||||
Params=SelectParams Theme="SelectTheme.Sort" >
|
Params=SelectParams Theme="SelectTheme.Sort" >
|
||||||
<div class="square-button">
|
<div class="square-button">
|
||||||
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
<div class="search-container">
|
<div class="search-container">
|
||||||
<SearchInput @bind-Text="@Value.Title"
|
<SearchInput @bind-Text="@Value.Title"
|
||||||
|
@bind-Text:after="HandleValueChanged"
|
||||||
Placeholder="@ResourcesKey.Research" />
|
Placeholder="@ResourcesKey.Research" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,33 @@
|
|||||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.SliderRange;
|
using GameIdeas.BlazorApp.Shared.Components.SliderRange;
|
||||||
using GameIdeas.BlazorApp.Shared.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Enum;
|
using GameIdeas.Shared.Enum;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Forms;
|
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
|
|
||||||
public partial class GameFilter
|
public partial class GameFilter
|
||||||
{
|
{
|
||||||
[Parameter] public GameFilterDto Value { get; set; } = new();
|
[Parameter] public GameFilterParams Value { get; set; } = new();
|
||||||
[Parameter] public EventCallback<GameFilterDto> ValueChanged { get; set; }
|
[Parameter] public EventCallback<GameFilterParams> ValueChanged { get; set; }
|
||||||
[Parameter] public DisplayType DisplayType { get; set; }
|
[Parameter] public DisplayType DisplayType { get; set; }
|
||||||
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
||||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||||
|
|
||||||
|
public static readonly List<SortTypeDto> SortTypes = [
|
||||||
private readonly List<SortTypeDto> SortTypes = [
|
new() { SortType = SortType.Ascending, Label = ResourcesKey.Ascending },
|
||||||
new() { SortType = SortType.Ascending, Label = "Ascendant" },
|
new() { SortType = SortType.Descending, Label = ResourcesKey.Descending }
|
||||||
new() { SortType = SortType.Descending, Label = "Descendant" }
|
|
||||||
];
|
];
|
||||||
|
|
||||||
private readonly List<SortPropertyDto> GameProperties = [
|
public static readonly List<SortPropertyDto> GameProperties = [
|
||||||
new() { SortProperty = game => game.Title!, Label = "Titre" },
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Title), Label = ResourcesKey.Title },
|
||||||
new() { SortProperty = game => game.ReleaseDate!, Label = "Date de parution" }
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ReleaseDate), Label = ResourcesKey.ReleaseDate },
|
||||||
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.CreationDate), Label = ResourcesKey.CreateDate },
|
||||||
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ModificationDate), Label = ResourcesKey.UpdateDate },
|
||||||
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.StorageSpace), Label = ResourcesKey.StorageSize },
|
||||||
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Interest), Label = ResourcesKey.Interest }
|
||||||
];
|
];
|
||||||
|
|
||||||
private SelectParams<SortPropertyDto, SortTypeDto> SelectParams = new();
|
private SelectParams<SortPropertyDto, SortTypeDto> SelectParams = new();
|
||||||
@@ -36,10 +39,8 @@ public partial class GameFilter
|
|||||||
{
|
{
|
||||||
Headers = SortTypes,
|
Headers = SortTypes,
|
||||||
GetHeaderLabel = header => header.Label,
|
GetHeaderLabel = header => header.Label,
|
||||||
DefaultHeaders = SortTypes.Where(h => h.SortType == SortType.Ascending).ToList(),
|
|
||||||
Items = GameProperties,
|
Items = GameProperties,
|
||||||
GetItemLabel = item => item.Label,
|
GetItemLabel = item => item.Label,
|
||||||
DefaultItems = GameProperties.Where(p => p.Label == "Titre").ToList()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
|
|
||||||
|
public class GameFilterParams
|
||||||
|
{
|
||||||
|
public SortTypeDto? SortType { get; set; }
|
||||||
|
public SortPropertyDto? SortProperty { get; set; }
|
||||||
|
public string? Title { get; set; }
|
||||||
|
public List<PlatformDto>? Platforms { get; set; }
|
||||||
|
public List<PropertyDto>? Properties { get; set; }
|
||||||
|
public List<TagDto>? Tags { get; set; }
|
||||||
|
public List<PublisherDto>? Publishers { get; set; }
|
||||||
|
public List<DeveloperDto>? Developers { get; set; }
|
||||||
|
public int MinInterest { get; set; } = 1;
|
||||||
|
public int MaxInterest { get; set; } = 5;
|
||||||
|
public List<int>? ReleaseYears { get; set; }
|
||||||
|
public List<int>? StorageSpaceIds { get; set; }
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<GameHeader AddTypeChanged="HandleAddClicked">
|
<GameHeader AddTypeChanged="HandleAddClicked">
|
||||||
<GameFilter Categories="Categories"
|
<GameFilter Categories="Categories"
|
||||||
@bind-DisplayType=DisplayType
|
@bind-DisplayType=DisplayType
|
||||||
@bind-Value=GameFilter />
|
Value=GameFilter ValueChanged="HandleFilterChanged" />
|
||||||
</GameHeader>
|
</GameHeader>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -36,9 +36,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AdvancedGameFilter @bind-GameFilter=GameFilter Categories="Categories" />
|
<AdvancedGameFilter GameFilter=GameFilter GameFilterChanged="HandleFilterChanged" Categories="Categories" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
||||||
<GameCreationForm Categories="Categories" OnSubmit="HandleFetchDatas" />
|
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
|
||||||
</Popup>
|
</Popup>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
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.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
|
using GameIdeas.Shared.Enum;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||||
@@ -11,17 +13,26 @@ public partial class Game
|
|||||||
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
||||||
|
|
||||||
private DisplayType DisplayType = DisplayType.List;
|
private DisplayType DisplayType = DisplayType.List;
|
||||||
private GameFilterDto GameFilter = new();
|
private GameFilterParams GameFilter = new();
|
||||||
private Popup? ManualAddPopup;
|
private Popup? ManualAddPopup;
|
||||||
private bool IsLoading = false;
|
private bool IsLoading = false;
|
||||||
private CategoriesDto? Categories;
|
private CategoriesDto? Categories;
|
||||||
private IEnumerable<GameDto> GamesDto = [];
|
private IEnumerable<GameDto> GamesDto = [];
|
||||||
|
private int CurrentPage;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
CurrentPage = 1;
|
||||||
|
GameFilter.SortType = Filter.GameFilter.SortTypes
|
||||||
|
.First(st => st.SortType == SortType.Ascending);
|
||||||
|
|
||||||
|
GameFilter.SortProperty= Filter.GameFilter.GameProperties
|
||||||
|
.First(gp => gp.PropertyName == nameof(GameIdeas.Shared.Model.Game.Title));
|
||||||
|
|
||||||
await HandleFetchDatas();
|
await HandleFetchDatas();
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleAddClicked(AddType addType)
|
private void HandleAddClicked(AddType addType)
|
||||||
{
|
{
|
||||||
switch (addType)
|
switch (addType)
|
||||||
@@ -39,14 +50,16 @@ public partial class Game
|
|||||||
{
|
{
|
||||||
ManualAddPopup?.Close();
|
ManualAddPopup?.Close();
|
||||||
}
|
}
|
||||||
private async Task HandleFetchDatas()
|
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = displayLoader;
|
||||||
|
|
||||||
|
if (loadCategories)
|
||||||
Categories = await GameGateway.FetchCategories();
|
Categories = await GameGateway.FetchCategories();
|
||||||
GamesDto = await GameGateway.FetchGames(new PaggingDto() { CurrentPage = 1, NumberPerPage = 50 });
|
|
||||||
|
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -57,4 +70,9 @@ public partial class Game
|
|||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async Task HandleFilterChanged(GameFilterParams args)
|
||||||
|
{
|
||||||
|
GameFilter = args;
|
||||||
|
await HandleFetchDatas(loadCategories: false, displayLoader: false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using GameIdeas.BlazorApp.Services;
|
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
|
using GameIdeas.BlazorApp.Services;
|
||||||
using GameIdeas.BlazorApp.Shared.Constants;
|
using GameIdeas.BlazorApp.Shared.Constants;
|
||||||
using GameIdeas.BlazorApp.Shared.Exceptions;
|
using GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
using GameIdeas.Resources;
|
using GameIdeas.Resources;
|
||||||
@@ -8,7 +9,7 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|||||||
|
|
||||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||||
{
|
{
|
||||||
public async Task<int> CreateGame(GameDto game)
|
public async Task<int> CreateGame(GameDetailDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -34,11 +35,26 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging)
|
public async Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filterParams, int currentPage)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(pagging));
|
GameFilterDto filter = new()
|
||||||
|
{
|
||||||
|
CurrentPage = currentPage,
|
||||||
|
Title = filterParams.Title,
|
||||||
|
MaxInterest = filterParams.MaxInterest,
|
||||||
|
MinInterest = filterParams.MinInterest,
|
||||||
|
StorageSpaces = filterParams.StorageSpaceIds,
|
||||||
|
DeveloperIds = filterParams.Developers?.Select(d => d.Id ?? 0).ToList(),
|
||||||
|
PublisherIds = filterParams.Publishers?.Select(d => d.Id ?? 0).ToList(),
|
||||||
|
PlatformIds = filterParams.Platforms?.Select(d => d.Id ?? 0).ToList(),
|
||||||
|
PropertyIds = filterParams.Properties?.Select(d => d.Id ?? 0).ToList(),
|
||||||
|
ReleaseYears = filterParams.ReleaseYears,
|
||||||
|
TagIds = filterParams.Tags?.Select(d => d.Id ?? 0).ToList(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(filter));
|
||||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
|
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||||
|
|
||||||
public interface IGameGateway
|
public interface IGameGateway
|
||||||
{
|
{
|
||||||
Task<CategoriesDto> FetchCategories();
|
Task<CategoriesDto> FetchCategories();
|
||||||
Task<int> CreateGame(GameDto game);
|
Task<int> CreateGame(GameDetailDto game);
|
||||||
Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging);
|
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ public partial class GameHeader : ComponentBase
|
|||||||
SelectParams = new()
|
SelectParams = new()
|
||||||
{
|
{
|
||||||
Items = AddTypes.ToList(),
|
Items = AddTypes.ToList(),
|
||||||
GetItemLabel = item => item.Value,
|
GetItemLabel = item => item.Value
|
||||||
DefaultItems = []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
@using GameIdeas.Shared.Constants
|
@using GameIdeas.Shared.Constants
|
||||||
|
|
||||||
<div class="search-container">
|
<div class="search-container">
|
||||||
<input @ref=InputText
|
<input id="searchInput"
|
||||||
type="text"
|
type="text"
|
||||||
class="search-field"
|
class="search-field"
|
||||||
placeholder="@Placeholder"
|
placeholder="@Placeholder"
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
style="@(IsDisable ? "pointer-events: none" : "")"
|
style="@(IsDisable ? "pointer-events: none" : "")"
|
||||||
@bind=@Text
|
@bind=@Text
|
||||||
@bind:event="oninput"
|
@bind:event="oninput"
|
||||||
@bind:after=HandleTextChanged
|
@bind:after="HandleTextChanged"
|
||||||
@onfocusin=HandleFocusIn/>
|
@onfocusin=HandleFocusIn/>
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
@@ -26,4 +26,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using GameIdeas.BlazorApp.Shared.Constants;
|
using GameIdeas.BlazorApp.Shared.Constants;
|
||||||
using GameIdeas.Shared.Constants;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Shared.Components.Search;
|
namespace GameIdeas.BlazorApp.Shared.Components.Search;
|
||||||
@@ -15,11 +14,20 @@ public partial class SearchInput
|
|||||||
[Parameter] public EventCallback FocusIn { get; set; }
|
[Parameter] public EventCallback FocusIn { get; set; }
|
||||||
[Parameter] public SearchInputIcon Icon { get; set; }
|
[Parameter] public SearchInputIcon Icon { get; set; }
|
||||||
|
|
||||||
private ElementReference InputText;
|
private System.Timers.Timer? Timer;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
Text = string.Empty;
|
Text = string.Empty;
|
||||||
|
Timer = new()
|
||||||
|
{
|
||||||
|
Interval = 500,
|
||||||
|
AutoReset = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
Timer.Elapsed += async (_, _) => await TextChanged.InvokeAsync(Text);
|
||||||
|
|
||||||
|
base.OnInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetText(string str)
|
public void SetText(string str)
|
||||||
@@ -27,9 +35,10 @@ public partial class SearchInput
|
|||||||
Text = str;
|
Text = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleTextChanged()
|
private void HandleTextChanged()
|
||||||
{
|
{
|
||||||
await TextChanged.InvokeAsync(Text);
|
Timer?.Stop();
|
||||||
|
Timer?.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleClearClicked()
|
private async Task HandleClearClicked()
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
public class SelectParams<TItem, THeader>
|
public class SelectParams<TItem, THeader>
|
||||||
{
|
{
|
||||||
public List<TItem> Items { get; set; } = [];
|
public List<TItem> Items { get; set; } = [];
|
||||||
public List<TItem> DefaultItems { get; set; } = [];
|
|
||||||
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
|
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
|
||||||
public List<THeader> Headers { get; set; } = [];
|
public List<THeader> Headers { get; set; } = [];
|
||||||
public List<THeader> DefaultHeaders { get; set; } = [];
|
|
||||||
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
|
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
|
||||||
public Func<string, TItem>? AddItem { get; set; }
|
public Func<string, TItem>? AddItem { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -37,16 +37,6 @@ public partial class Select<TItem, THeader>
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
QuickAddEditContext = new EditContext(AddLabel);
|
QuickAddEditContext = new EditContext(AddLabel);
|
||||||
|
|
||||||
if (Params.DefaultItems.Count != 0)
|
|
||||||
{
|
|
||||||
Values.AddRange(Params.DefaultItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Params.DefaultHeaders.Count != 0)
|
|
||||||
{
|
|
||||||
HeaderValues.AddRange(Params.DefaultHeaders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleButtonClicked()
|
private void HandleButtonClicked()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.BlazorApp.Helpers;
|
||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Shared.Constants;
|
namespace GameIdeas.BlazorApp.Shared.Constants;
|
||||||
|
|
||||||
@@ -7,8 +8,7 @@ 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) =>
|
public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}";
|
||||||
$"api/Game?{nameof(pagging.CurrentPage)}={pagging.CurrentPage}&{nameof(pagging.NumberPerPage)}={pagging.NumberPerPage}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Category
|
public static class Category
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<script src="_framework/blazor.webassembly.js"></script>
|
<script src="_framework/blazor.webassembly.js"></script>
|
||||||
<script src="Shared/Components/BackdropFilter/BackdropFilter.razor.js"></script>
|
<script src="Shared/Components/BackdropFilter/BackdropFilter.razor.js"></script>
|
||||||
<script src="Shared/Components/Select/MultipleSelectList.razor.js"></script>
|
|
||||||
<script src="Pages/Games/Components/GameCreationForm.razor.js"></script>
|
<script src="Pages/Games/Components/GameCreationForm.razor.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class Translations (TranslationService translationService)
|
|||||||
public string StorageSizeMo => translationService.Translate(nameof(StorageSizeMo));
|
public string StorageSizeMo => translationService.Translate(nameof(StorageSizeMo));
|
||||||
public string LastModification => translationService.Translate(nameof(LastModification));
|
public string LastModification => translationService.Translate(nameof(LastModification));
|
||||||
public string ReleaseDate => translationService.Translate(nameof(ReleaseDate));
|
public string ReleaseDate => translationService.Translate(nameof(ReleaseDate));
|
||||||
|
public string CreateDate => translationService.Translate(nameof(CreateDate));
|
||||||
|
public string UpdateDate => translationService.Translate(nameof(UpdateDate));
|
||||||
public string Title => translationService.Translate(nameof(Title));
|
public string Title => translationService.Translate(nameof(Title));
|
||||||
public string Interest => translationService.Translate(nameof(Interest));
|
public string Interest => translationService.Translate(nameof(Interest));
|
||||||
public string Properties => translationService.Translate(nameof(Properties));
|
public string Properties => translationService.Translate(nameof(Properties));
|
||||||
@@ -40,6 +42,12 @@ public class Translations (TranslationService translationService)
|
|||||||
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 string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
||||||
|
public string Ascending => translationService.Translate(nameof(Ascending));
|
||||||
|
public string Descending => translationService.Translate(nameof(Descending));
|
||||||
|
public string ErrorStorageSpaceLabel => translationService.Translate(nameof(ErrorStorageSpaceLabel));
|
||||||
|
public string MinStorageSpaceFormat => translationService.Translate(nameof(MinStorageSpaceFormat));
|
||||||
|
public string MaxStorageSpaceFormat => translationService.Translate(nameof(MaxStorageSpaceFormat));
|
||||||
|
public string MinMaxStorageSpaceFormat => translationService.Translate(nameof(MinMaxStorageSpaceFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourcesKey
|
public static class ResourcesKey
|
||||||
@@ -70,6 +78,8 @@ public static class ResourcesKey
|
|||||||
public static string StorageSizeMo => _instance?.StorageSizeMo ?? throw new InvalidOperationException("ResourcesKey.StorageSizeMo is not initialized.");
|
public static string StorageSizeMo => _instance?.StorageSizeMo ?? throw new InvalidOperationException("ResourcesKey.StorageSizeMo is not initialized.");
|
||||||
public static string LastModification => _instance?.LastModification ?? throw new InvalidOperationException("ResourcesKey.LastModification is not initialized.");
|
public static string LastModification => _instance?.LastModification ?? throw new InvalidOperationException("ResourcesKey.LastModification is not initialized.");
|
||||||
public static string ReleaseDate => _instance?.ReleaseDate ?? throw new InvalidOperationException("ResourcesKey.ReleaseDate is not initialized.");
|
public static string ReleaseDate => _instance?.ReleaseDate ?? throw new InvalidOperationException("ResourcesKey.ReleaseDate is not initialized.");
|
||||||
|
public static string CreateDate => _instance?.CreateDate ?? throw new InvalidOperationException("ResourcesKey.CreateDate is not initialized.");
|
||||||
|
public static string UpdateDate => _instance?.UpdateDate ?? throw new InvalidOperationException("ResourcesKey.UpdateDate is not initialized.");
|
||||||
public static string Title => _instance?.Title ?? throw new InvalidOperationException("ResourcesKey.Title is not initialized.");
|
public static string Title => _instance?.Title ?? throw new InvalidOperationException("ResourcesKey.Title is not initialized.");
|
||||||
public static string Interest => _instance?.Interest ?? throw new InvalidOperationException("ResourcesKey.Interest is not initialized.");
|
public static string Interest => _instance?.Interest ?? throw new InvalidOperationException("ResourcesKey.Interest is not initialized.");
|
||||||
public static string Properties => _instance?.Properties ?? throw new InvalidOperationException("ResourcesKey.Properties is not initialized.");
|
public static string Properties => _instance?.Properties ?? throw new InvalidOperationException("ResourcesKey.Properties is not initialized.");
|
||||||
@@ -88,4 +98,10 @@ public static class ResourcesKey
|
|||||||
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.");
|
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
||||||
|
public static string Ascending => _instance?.Ascending ?? throw new InvalidOperationException("ResourcesKey.Ascending is not initialized.");
|
||||||
|
public static string Descending => _instance?.Descending ?? throw new InvalidOperationException("ResourcesKey.Descending is not initialized.");
|
||||||
|
public static string ErrorStorageSpaceLabel => _instance?.ErrorStorageSpaceLabel ?? throw new InvalidOperationException("ResourcesKey.ErrorStorageSpaceLabel is not initialized.");
|
||||||
|
public static string MinStorageSpaceFormat => _instance?.MinStorageSpaceFormat ?? throw new InvalidOperationException("ResourcesKey.MinStorageSpaceFormat is not initialized.");
|
||||||
|
public static string MaxStorageSpaceFormat => _instance?.MaxStorageSpaceFormat ?? throw new InvalidOperationException("ResourcesKey.MaxStorageSpaceFormat is not initialized.");
|
||||||
|
public static string MinMaxStorageSpaceFormat => _instance?.MinMaxStorageSpaceFormat ?? throw new InvalidOperationException("ResourcesKey.MinMaxStorageSpaceFormat is not initialized.");
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public class GlobalConstants
|
public class GlobalConstants
|
||||||
{
|
{
|
||||||
|
public static int NUMBER_PER_PAGE = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,4 +7,6 @@ public class CategoriesDto
|
|||||||
public List<TagDto>? Tags { get; set; }
|
public List<TagDto>? Tags { get; set; }
|
||||||
public List<DeveloperDto>? Developers { get; set; }
|
public List<DeveloperDto>? Developers { get; set; }
|
||||||
public List<PublisherDto>? Publishers { get; set; }
|
public List<PublisherDto>? Publishers { get; set; }
|
||||||
|
public List<int>? ReleaseYears { get; set; }
|
||||||
|
public List<StorageSpaceDto>? StorageSpaces { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/GameIdeas/GameIdeas.Shared/Dto/GameDetailDto.cs
Normal file
20
src/GameIdeas/GameIdeas.Shared/Dto/GameDetailDto.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
public class GameDetailDto
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? Title { get; set; }
|
||||||
|
public DateTime? ReleaseDate { get; set; }
|
||||||
|
public DateTime? CreationDate { get; set; }
|
||||||
|
public int CreationUserId { get; set; }
|
||||||
|
public DateTime? ModificationDate { get; set; }
|
||||||
|
public int? ModificationUserId { get; set; }
|
||||||
|
public double? StorageSpace { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public int Interest { get; set; } = 3;
|
||||||
|
public List<PlatformDto>? Platforms { get; set; }
|
||||||
|
public List<PropertyDto>? Properties { get; set; }
|
||||||
|
public List<TagDto>? Tags { get; set; }
|
||||||
|
public List<PublisherDto>? Publishers { get; set; }
|
||||||
|
public List<DeveloperDto>? Developers { get; set; }
|
||||||
|
}
|
||||||
@@ -5,18 +5,8 @@ public class GameDto
|
|||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
public DateTime? ReleaseDate { get; set; }
|
public DateTime? ReleaseDate { get; set; }
|
||||||
public DateTime? CreationDate { get; set; }
|
public IEnumerable<PlatformDto>? Platforms { get; set; }
|
||||||
public UserDto? CreationUser { get; set; }
|
public IEnumerable<TagDto>? Tags { get; set; }
|
||||||
public int CreationUserId { get; set; }
|
|
||||||
public DateTime? ModificationDate { get; set; }
|
|
||||||
public UserDto? ModificationUser { get; set; }
|
|
||||||
public int? ModificationUserId { get; set; }
|
|
||||||
public double? StorageSpace { get; set; }
|
public double? StorageSpace { get; set; }
|
||||||
public string? Description { get; set; }
|
|
||||||
public int Interest { get; set; } = 3;
|
public int Interest { get; set; } = 3;
|
||||||
public List<PlatformDto>? Platforms { get; set; }
|
|
||||||
public List<PropertyDto>? Properties { get; set; }
|
|
||||||
public List<TagDto>? Tags { get; set; }
|
|
||||||
public List<PublisherDto>? Publishers { get; set; }
|
|
||||||
public List<DeveloperDto>? Developers { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
|
using GameIdeas.Shared.Enum;
|
||||||
|
|
||||||
namespace GameIdeas.Shared.Dto;
|
namespace GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
public class GameFilterDto
|
public class GameFilterDto
|
||||||
{
|
{
|
||||||
public SortTypeDto? SortType { get; set; }
|
public int CurrentPage { get; set; } = 1;
|
||||||
public SortPropertyDto? SortProperty { get; set; }
|
public SortType? SortType { get; set; }
|
||||||
|
public string? SortPropertyName { get; set; }
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
public List<PlatformDto>? Platforms { get; set; }
|
public List<int>? PlatformIds { get; set; }
|
||||||
public List<PropertyDto>? Properties { get; set; }
|
public List<int>? PropertyIds { get; set; }
|
||||||
public List<TagDto>? Tags { get; set; }
|
public List<int>? TagIds { get; set; }
|
||||||
public List<PublisherDto>? Publishers { get; set; }
|
public List<int>? PublisherIds { get; set; }
|
||||||
public List<DeveloperDto>? Developers { get; set; }
|
public List<int>? DeveloperIds { get; set; }
|
||||||
public int MinInterest { get; set; } = 1;
|
public int? MinInterest { get; set; }
|
||||||
public int MaxInterest { get; set; } = 5;
|
public int? MaxInterest { get; set; }
|
||||||
public List<int>? ReleaseYears { get; set; }
|
public List<int>? ReleaseYears { get; set; }
|
||||||
public int? MinStorageSize { get; set; }
|
public List<int>? StorageSpaces { get; set; }
|
||||||
public int? MaxStorageSize { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace GameIdeas.Shared.Dto;
|
|
||||||
|
|
||||||
public class PaggingDto
|
|
||||||
{
|
|
||||||
public int CurrentPage { get; set; }
|
|
||||||
public int NumberPerPage { get; set; }
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public class SortPropertyDto
|
public class SortPropertyDto
|
||||||
{
|
{
|
||||||
public Func<GameDto, object>? SortProperty { get; set; }
|
public string PropertyName { get; set; } = string.Empty;
|
||||||
public string Label { get; set; } = string.Empty;
|
public string Label { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/GameIdeas/GameIdeas.Shared/Dto/StorageSpaceDto.cs
Normal file
8
src/GameIdeas/GameIdeas.Shared/Dto/StorageSpaceDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
public class StorageSpaceDto
|
||||||
|
{
|
||||||
|
public int? MinSize { get; set; }
|
||||||
|
public int? MaxSize { get; set; }
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.WebAPI.Services.Interfaces;
|
using GameIdeas.WebAPI.Services.Categories;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Controllers;
|
namespace GameIdeas.WebAPI.Controllers;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.WebAPI.Services.Interfaces;
|
using GameIdeas.WebAPI.Services.Games;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Controllers;
|
namespace GameIdeas.WebAPI.Controllers;
|
||||||
@@ -7,16 +7,19 @@ namespace GameIdeas.WebAPI.Controllers;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
|
|
||||||
public class GameController(IGameService gameService, ILoggerFactory loggerFactory) : Controller
|
public class GameController(
|
||||||
|
IGameReadService gameReadService,
|
||||||
|
IGameWriteService gameWriteService,
|
||||||
|
ILoggerFactory loggerFactory) : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<IEnumerable<GameDto>>> GetGames([FromQuery] PaggingDto pagging)
|
public async Task<ActionResult<IEnumerable<GameDto>>> SearchGames([FromQuery] GameFilterDto filter)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Ok(await gameService.GetGames(pagging));
|
return Ok(await gameReadService.GetGames(filter));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -26,11 +29,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id:int}")]
|
[HttpGet("{id:int}")]
|
||||||
public async Task<ActionResult<GameDto>> GetGameById(int id)
|
public async Task<ActionResult<GameDetailDto>> GetGameById(int id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Ok(await gameService.GetGameById(id));
|
return Ok(await gameReadService.GetGameById(id));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -40,11 +43,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("Create")]
|
[HttpPost("Create")]
|
||||||
public async Task<ActionResult<int>> CreateGame([FromBody] GameDto game)
|
public async Task<ActionResult<int>> CreateGame([FromBody] GameDetailDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var gameResult = await gameService.CreateGame(game);
|
var gameResult = await gameWriteService.CreateGame(game);
|
||||||
return Created("/Create", gameResult.Id);
|
return Created("/Create", gameResult.Id);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -55,11 +58,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("Update")]
|
[HttpPut("Update")]
|
||||||
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDto game)
|
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDetailDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var gameResult = await gameService.UpdateGame(game);
|
var gameResult = await gameWriteService.UpdateGame(game);
|
||||||
return Created($"/Update", gameResult.Id);
|
return Created($"/Update", gameResult.Id);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -74,7 +77,7 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Ok(await gameService.DeleteGame(id));
|
return Ok(await gameWriteService.DeleteGame(id));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
"StorageSizeMo": "Taille d'espace en Mo",
|
"StorageSizeMo": "Taille d'espace en Mo",
|
||||||
"LastModification": "Dernière modifications",
|
"LastModification": "Dernière modifications",
|
||||||
"ReleaseDate": "Date de parution",
|
"ReleaseDate": "Date de parution",
|
||||||
|
"CreateDate": "Date de création",
|
||||||
|
"UpdateDate": "Date de modification",
|
||||||
"Title": "Titre",
|
"Title": "Titre",
|
||||||
"Interest": "Intérêt",
|
"Interest": "Intérêt",
|
||||||
"Properties": "Propriétés",
|
"Properties": "Propriétés",
|
||||||
@@ -35,6 +37,11 @@
|
|||||||
"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"
|
"ErrorFetchGames": "Erreur lors de la récupération des jeux",
|
||||||
|
"Ascending": "Ascendant",
|
||||||
|
"Descending": "Descendant",
|
||||||
|
"ErrorStorageSpaceLabel": "Erreur lors de la génération des label de l'espace de stockage",
|
||||||
|
"MinStorageSpaceFormat": "Jusqu'à {0}",
|
||||||
|
"MaxStorageSpaceFormat": "Plus de {0}",
|
||||||
|
"MinMaxStorageSpaceFormat": "{0} à {1}"
|
||||||
}
|
}
|
||||||
@@ -8,16 +8,14 @@ public class GameProfile : Profile
|
|||||||
{
|
{
|
||||||
public GameProfile()
|
public GameProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Game, GameDto>()
|
CreateMap<Game, GameDetailDto>()
|
||||||
.ForMember(d => d.Id, o => o.MapFrom(s => s.Id))
|
.ForMember(d => d.Id, o => o.MapFrom(s => s.Id))
|
||||||
.ForMember(d => d.Title, o => o.MapFrom(s => s.Title))
|
.ForMember(d => d.Title, o => o.MapFrom(s => s.Title))
|
||||||
.ForMember(d => d.ReleaseDate, o => o.MapFrom(s => s.ReleaseDate))
|
.ForMember(d => d.ReleaseDate, o => o.MapFrom(s => s.ReleaseDate))
|
||||||
.ForMember(d => d.CreationDate, o => o.MapFrom(s => s.CreationDate))
|
.ForMember(d => d.CreationDate, o => o.MapFrom(s => s.CreationDate))
|
||||||
.ForMember(d => d.CreationUserId, o => o.MapFrom(s => s.CreationUserId))
|
.ForMember(d => d.CreationUserId, o => o.MapFrom(s => s.CreationUserId))
|
||||||
.ForMember(d => d.CreationUser, o => o.MapFrom(s => s.CreationUser))
|
|
||||||
.ForMember(d => d.ModificationDate, o => o.MapFrom(s => s.ModificationDate))
|
.ForMember(d => d.ModificationDate, o => o.MapFrom(s => s.ModificationDate))
|
||||||
.ForMember(d => d.ModificationUserId, o => o.MapFrom(s => s.ModificationUserId))
|
.ForMember(d => d.ModificationUserId, o => o.MapFrom(s => s.ModificationUserId))
|
||||||
.ForMember(d => d.ModificationUser, o => o.MapFrom(s => s.ModificationUser))
|
|
||||||
.ForMember(d => d.StorageSpace, o => o.MapFrom(s => s.StorageSpace))
|
.ForMember(d => d.StorageSpace, o => o.MapFrom(s => s.StorageSpace))
|
||||||
.ForMember(d => d.Description, o => o.MapFrom(s => s.Description))
|
.ForMember(d => d.Description, o => o.MapFrom(s => s.Description))
|
||||||
.ForMember(d => d.Interest, o => o.MapFrom(s => s.Interest))
|
.ForMember(d => d.Interest, o => o.MapFrom(s => s.Interest))
|
||||||
@@ -27,5 +25,15 @@ public class GameProfile : Profile
|
|||||||
.ForMember(d => d.Publishers, o => o.MapFrom(s => s.GamePublishers.Select(p => p.Publisher)))
|
.ForMember(d => d.Publishers, o => o.MapFrom(s => s.GamePublishers.Select(p => p.Publisher)))
|
||||||
.ForMember(d => d.Developers, o => o.MapFrom(s => s.GameDevelopers.Select(gd => gd.Developer)))
|
.ForMember(d => d.Developers, o => o.MapFrom(s => s.GameDevelopers.Select(gd => gd.Developer)))
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
CreateMap<Game, GameDto>()
|
||||||
|
.ForMember(d => d.Id, o => o.MapFrom(s => s.Id))
|
||||||
|
.ForMember(d => d.Title, o => o.MapFrom(s => s.Title))
|
||||||
|
.ForMember(d => d.ReleaseDate, o => o.MapFrom(s => s.ReleaseDate))
|
||||||
|
.ForMember(d => d.Platforms, o => o.MapFrom(s => s.GamePlatforms.Select(p => new PlatformDto() { Id = p.Platform.Id, Label = p.Platform.Label, Url = p.Url })))
|
||||||
|
.ForMember(d => d.Tags, o => o.MapFrom(s => s.GameTags.Select(t => t.Tag)))
|
||||||
|
.ForMember(d => d.StorageSpace, o => o.MapFrom(s => s.StorageSpace))
|
||||||
|
.ForMember(d => d.Interest, o => o.MapFrom(s => s.Interest))
|
||||||
|
.ReverseMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
using GameIdeas.Resources;
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.WebAPI.Context;
|
using GameIdeas.WebAPI.Context;
|
||||||
using GameIdeas.WebAPI.Profiles;
|
using GameIdeas.WebAPI.Services.Categories;
|
||||||
using GameIdeas.WebAPI.Services;
|
using GameIdeas.WebAPI.Services.Games;
|
||||||
using GameIdeas.WebAPI.Services.Interfaces;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
var services = builder.Services;
|
var services = builder.Services;
|
||||||
@@ -32,7 +30,8 @@ services.AddDbContext<GameIdeasContext>(dbContextOptions);
|
|||||||
services.AddSingleton<TranslationService>();
|
services.AddSingleton<TranslationService>();
|
||||||
services.AddSingleton<Translations>();
|
services.AddSingleton<Translations>();
|
||||||
|
|
||||||
services.AddScoped<IGameService, GameService>();
|
services.AddScoped<IGameReadService, GameReadService>();
|
||||||
|
services.AddScoped<IGameWriteService, GameWriteService>();
|
||||||
services.AddScoped<ICategoryService, CategoryService>();
|
services.AddScoped<ICategoryService, CategoryService>();
|
||||||
|
|
||||||
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.WebAPI.Context;
|
using GameIdeas.WebAPI.Context;
|
||||||
using GameIdeas.WebAPI.Services.Interfaces;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services;
|
namespace GameIdeas.WebAPI.Services.Categories;
|
||||||
|
|
||||||
public class CategoryService(GameIdeasContext context, IMapper mapper) : ICategoryService
|
public class CategoryService(GameIdeasContext context, IMapper mapper) : ICategoryService
|
||||||
{
|
{
|
||||||
|
public List<StorageSpaceDto> GetStorageSpaces() => [
|
||||||
|
new() { Id = 1, MaxSize = 100 },
|
||||||
|
new() { Id = 2, MinSize = 100, MaxSize = 1000 },
|
||||||
|
new() { Id = 3, MinSize = 1000, MaxSize = 5000 },
|
||||||
|
new() { Id = 4, MinSize = 5000, MaxSize = 10000 },
|
||||||
|
new() { Id = 5, MinSize = 10000, MaxSize = 20000 },
|
||||||
|
new() { Id = 6, MinSize = 20000, MaxSize = 40000 },
|
||||||
|
new() { Id = 7, MinSize = 40000, MaxSize = 100000 },
|
||||||
|
new() { Id = 8, MinSize = 100000 },
|
||||||
|
];
|
||||||
|
|
||||||
public async Task<CategoriesDto> GetCategories()
|
public async Task<CategoriesDto> GetCategories()
|
||||||
{
|
{
|
||||||
var platforms = await context.Platforms.ToListAsync();
|
var platforms = await context.Platforms.ToListAsync();
|
||||||
@@ -15,6 +25,9 @@ public class CategoryService(GameIdeasContext context, IMapper mapper) : ICatego
|
|||||||
var tags = await context.Tags.ToListAsync();
|
var tags = await context.Tags.ToListAsync();
|
||||||
var developers = await context.Developers.ToListAsync();
|
var developers = await context.Developers.ToListAsync();
|
||||||
var publishers = await context.Publishers.ToListAsync();
|
var publishers = await context.Publishers.ToListAsync();
|
||||||
|
var releaseYears = await context.Games
|
||||||
|
.Where(game => game.ReleaseDate != null)
|
||||||
|
.Select(game => game.ReleaseDate!.Value.Year).Distinct().ToListAsync();
|
||||||
|
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
@@ -22,7 +35,9 @@ public class CategoryService(GameIdeasContext context, IMapper mapper) : ICatego
|
|||||||
Properties = mapper.Map<List<PropertyDto>>(properties),
|
Properties = mapper.Map<List<PropertyDto>>(properties),
|
||||||
Tags = mapper.Map<List<TagDto>>(tags),
|
Tags = mapper.Map<List<TagDto>>(tags),
|
||||||
Developers = mapper.Map<List<DeveloperDto>>(developers),
|
Developers = mapper.Map<List<DeveloperDto>>(developers),
|
||||||
Publishers = mapper.Map<List<PublisherDto>>(publishers)
|
Publishers = mapper.Map<List<PublisherDto>>(publishers),
|
||||||
|
ReleaseYears = mapper.Map<List<int>>(releaseYears),
|
||||||
|
StorageSpaces = GetStorageSpaces()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services.Interfaces;
|
namespace GameIdeas.WebAPI.Services.Categories;
|
||||||
|
|
||||||
public interface ICategoryService
|
public interface ICategoryService
|
||||||
{
|
{
|
||||||
|
List<StorageSpaceDto> GetStorageSpaces();
|
||||||
Task<CategoriesDto> GetCategories();
|
Task<CategoriesDto> GetCategories();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using GameIdeas.Shared.Constants;
|
||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
using GameIdeas.Shared.Exceptions;
|
||||||
|
using GameIdeas.Shared.Model;
|
||||||
|
using GameIdeas.WebAPI.Context;
|
||||||
|
using GameIdeas.WebAPI.Services.Categories;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Services.Games;
|
||||||
|
|
||||||
|
public class GameReadService(GameIdeasContext context, IMapper mapper, ICategoryService categoryService) : IGameReadService
|
||||||
|
{
|
||||||
|
public async Task<IEnumerable<GameDto>> GetGames(GameFilterDto filter)
|
||||||
|
{
|
||||||
|
var query = context.Games
|
||||||
|
.Include(g => g.GamePlatforms).ThenInclude(gp => gp.Platform)
|
||||||
|
.Include(g => g.GameProperties)
|
||||||
|
.Include(g => g.GameTags).ThenInclude(gt => gt.Tag)
|
||||||
|
.Include(g => g.GamePublishers)
|
||||||
|
.Include(g => g.GameDevelopers)
|
||||||
|
.AsQueryable();
|
||||||
|
|
||||||
|
ApplyFilter(ref query, filter);
|
||||||
|
|
||||||
|
ApplyOrder(ref query, filter);
|
||||||
|
|
||||||
|
var games = await query.Skip((filter.CurrentPage - 1) * GlobalConstants.NUMBER_PER_PAGE)
|
||||||
|
.Take(GlobalConstants.NUMBER_PER_PAGE)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
ApplyStaticFilter(ref games, filter);
|
||||||
|
|
||||||
|
return mapper.Map<IEnumerable<GameDto>>(games);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<GameDetailDto> GetGameById(int gameId)
|
||||||
|
{
|
||||||
|
var game = await context.Games
|
||||||
|
.Include(g => g.CreationUser)
|
||||||
|
.Include(g => g.ModificationUser)
|
||||||
|
.Include(g => g.GamePlatforms).ThenInclude(p => p.Platform)
|
||||||
|
.Include(g => g.GameProperties).ThenInclude(p => p.Property)
|
||||||
|
.Include(g => g.GameTags).ThenInclude(p => p.Tag)
|
||||||
|
.Include(g => g.GamePublishers).ThenInclude(p => p.Publisher)
|
||||||
|
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
|
||||||
|
.FirstOrDefaultAsync(g => g.Id == gameId);
|
||||||
|
|
||||||
|
return game == null
|
||||||
|
? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context")
|
||||||
|
: mapper.Map<GameDetailDto>(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ApplyOrder(ref IQueryable<Game> query, GameFilterDto filter)
|
||||||
|
{
|
||||||
|
if (filter.SortType != null && filter.SortPropertyName != null)
|
||||||
|
{
|
||||||
|
var param = Expression.Parameter(typeof(Game), "x");
|
||||||
|
Expression propertyAccess = Expression.PropertyOrField(param, filter.SortPropertyName);
|
||||||
|
var converted = Expression.Convert(propertyAccess, typeof(object));
|
||||||
|
var lambda = Expression.Lambda<Func<Game, object>>(converted, param);
|
||||||
|
|
||||||
|
if (filter.SortType == Shared.Enum.SortType.Ascending)
|
||||||
|
{
|
||||||
|
query = Queryable.OrderBy(query, lambda);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = Queryable.OrderByDescending(query, lambda);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyFilter(ref IQueryable<Game> query, GameFilterDto filter)
|
||||||
|
{
|
||||||
|
if (filter.PlatformIds != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => filter.PlatformIds.All(plat =>
|
||||||
|
game.GamePlatforms.Any(gp => gp.PlatformId == plat)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.PropertyIds != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => filter.PropertyIds.All(prop =>
|
||||||
|
game.GameProperties.Any(gp => gp.PropertyId == prop)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.TagIds != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => filter.TagIds.All(tag =>
|
||||||
|
game.GameTags.Any(gt => gt.TagId == tag)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.PublisherIds != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => filter.PublisherIds.All(pub =>
|
||||||
|
game.GamePublishers.Any(gp => gp.PublisherId == pub)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.DeveloperIds != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => filter.DeveloperIds.All(dev =>
|
||||||
|
game.GameDevelopers.Any(gd => gd.DeveloperId == dev)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.MinInterest != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => game.Interest >= filter.MinInterest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.MaxInterest != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => game.Interest <= filter.MaxInterest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ReleaseYears != null)
|
||||||
|
{
|
||||||
|
query = query.Where(game => game.ReleaseDate != null &&
|
||||||
|
filter.ReleaseYears.Contains(game.ReleaseDate.Value.Year));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyStaticFilter(ref List<Game> games, GameFilterDto filter)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(filter.Title))
|
||||||
|
{
|
||||||
|
var keywords = filter.Title?
|
||||||
|
.Split([' '], StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(k => k.Trim())
|
||||||
|
.ToArray() ?? [];
|
||||||
|
|
||||||
|
games = games
|
||||||
|
.Where(game => keywords.All(
|
||||||
|
kw => game.Title.Contains(kw, StringComparison.OrdinalIgnoreCase)
|
||||||
|
))
|
||||||
|
.OrderBy(game => keywords.Min(kw =>
|
||||||
|
game.Title.IndexOf(kw, StringComparison.OrdinalIgnoreCase)
|
||||||
|
))
|
||||||
|
.ThenBy(game => game.Title.Length)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.StorageSpaces != null)
|
||||||
|
{
|
||||||
|
var storageSpaces = categoryService.GetStorageSpaces().Where(stor => filter.StorageSpaces.Contains(stor.Id));
|
||||||
|
|
||||||
|
games = games
|
||||||
|
.Where(game => storageSpaces.Any(stor =>
|
||||||
|
(stor.MinSize ?? int.MinValue) <= game.StorageSpace && (stor.MaxSize ?? int.MaxValue) > game.StorageSpace))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +1,16 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using GameIdeas.Shared.Constants;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Exceptions;
|
using GameIdeas.Shared.Exceptions;
|
||||||
using GameIdeas.Shared.Model;
|
using GameIdeas.Shared.Model;
|
||||||
using GameIdeas.WebAPI.Context;
|
using GameIdeas.WebAPI.Context;
|
||||||
using GameIdeas.WebAPI.Services.Interfaces;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services;
|
namespace GameIdeas.WebAPI.Services.Games;
|
||||||
|
|
||||||
public class GameService(GameIdeasContext context, IMapper mapper) : IGameService
|
public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameWriteService
|
||||||
{
|
{
|
||||||
public async Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging)
|
public async Task<GameDetailDto> CreateGame(GameDetailDto gameDto)
|
||||||
{
|
|
||||||
var games = await SelectGames()
|
|
||||||
.OrderBy(g => g.Title)
|
|
||||||
.Skip((pagging.CurrentPage - 1) * pagging.NumberPerPage)
|
|
||||||
.Take(pagging.NumberPerPage)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
return mapper.Map<IEnumerable<GameDto>>(games);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<GameDto> GetGameById(int gameId)
|
|
||||||
{
|
|
||||||
var game = await SelectGames()
|
|
||||||
.FirstOrDefaultAsync(g => g.Id == gameId);
|
|
||||||
|
|
||||||
return game == null
|
|
||||||
? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context")
|
|
||||||
: mapper.Map<GameDto>(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<GameDto> CreateGame(GameDto gameDto)
|
|
||||||
{
|
{
|
||||||
var gameToCreate = mapper.Map<Game>(gameDto);
|
var gameToCreate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
@@ -46,10 +25,10 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
|
|||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
return mapper.Map<GameDto>(gameToCreate);
|
return mapper.Map<GameDetailDto>(gameToCreate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GameDto> UpdateGame(GameDto gameDto)
|
public async Task<GameDetailDto> UpdateGame(GameDetailDto gameDto)
|
||||||
{
|
{
|
||||||
if (await context.Games.CountAsync(g => g.Id == gameDto.Id) == 0)
|
if (await context.Games.CountAsync(g => g.Id == gameDto.Id) == 0)
|
||||||
{
|
{
|
||||||
@@ -67,7 +46,7 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
|
|||||||
context.Games.Update(gameToUpdate);
|
context.Games.Update(gameToUpdate);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
return mapper.Map<GameDto>(gameToUpdate);
|
return mapper.Map<GameDetailDto>(gameToUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteGame(int gameId)
|
public async Task<bool> DeleteGame(int gameId)
|
||||||
@@ -80,19 +59,6 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
|
|||||||
return await context.SaveChangesAsync() != 0;
|
return await context.SaveChangesAsync() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<Game> SelectGames()
|
|
||||||
{
|
|
||||||
return context.Games
|
|
||||||
.Include(g => g.CreationUser)
|
|
||||||
.Include(g => g.ModificationUser)
|
|
||||||
.Include(g => g.GamePlatforms).ThenInclude(p => p.Platform)
|
|
||||||
.Include(g => g.GameProperties).ThenInclude(p => p.Property)
|
|
||||||
.Include(g => g.GameTags).ThenInclude(p => p.Tag)
|
|
||||||
.Include(g => g.GamePublishers).ThenInclude(p => p.Publisher)
|
|
||||||
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
|
|
||||||
.AsQueryable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandlePlatformsCreation(IEnumerable<PlatformDto>? categoriesToCreate, int gameId)
|
private async Task HandlePlatformsCreation(IEnumerable<PlatformDto>? categoriesToCreate, int gameId)
|
||||||
{
|
{
|
||||||
if (categoriesToCreate != null)
|
if (categoriesToCreate != null)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Services.Games;
|
||||||
|
|
||||||
|
public interface IGameReadService
|
||||||
|
{
|
||||||
|
Task<IEnumerable<GameDto>> GetGames(GameFilterDto filter);
|
||||||
|
Task<GameDetailDto> GetGameById(int gameId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Services.Games;
|
||||||
|
|
||||||
|
public interface IGameWriteService
|
||||||
|
{
|
||||||
|
Task<GameDetailDto> CreateGame(GameDetailDto gameDto);
|
||||||
|
Task<GameDetailDto> UpdateGame(GameDetailDto gameDto);
|
||||||
|
Task<bool> DeleteGame(int gameId);
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services.Interfaces;
|
|
||||||
|
|
||||||
public interface IGameService
|
|
||||||
{
|
|
||||||
Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging);
|
|
||||||
Task<GameDto> GetGameById(int gameId);
|
|
||||||
Task<GameDto> CreateGame(GameDto gameDto);
|
|
||||||
Task<GameDto> UpdateGame(GameDto gameDto);
|
|
||||||
Task<bool> DeleteGame(int gameId);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user