Fetch all categories for creation
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 55s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 55s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
@using GameIdeas.BlazorApp.Shared.Components.Select
|
||||
@using GameIdeas.BlazorApp.Shared.Components.Select.Models
|
||||
@using GameIdeas.BlazorApp.Shared.Components.Slider
|
||||
@using GameIdeas.Shared.Dto
|
||||
|
||||
<EditForm EditContext="EditContext">
|
||||
<EditForm EditContext="EditContext" OnSubmit="HandleOnSubmit">
|
||||
<div class="game-form">
|
||||
<div class="container">
|
||||
<div class="input-game">
|
||||
<div id="first-label" class="label">@ResourcesKey.Title :</div>
|
||||
<input type="text" class="title">
|
||||
<input type="text" class="title" @bind=GameDto.Title>
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
||||
<input type="date" class="date">
|
||||
<input type="date" class="date" @bind=GameDto.ReleaseDate>
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.StorageSize :</div>
|
||||
<input type="text" class="storage">
|
||||
<div class="label">@ResourcesKey.StorageSizeMo :</div>
|
||||
<input type="number" class="storage" @bind=GameDto.StorageSpace>
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Developers :</div>
|
||||
<MultipleSelectList TItem="DeveloperDto" Theme="SelectListTheme" />
|
||||
<MultipleSelectList TItem="DeveloperDto" Theme="SelectListTheme" @bind-Values=GameDto.Developers
|
||||
Items="CategoriesDto?.Developers?.Select(d => new SelectElement<DeveloperDto>(d, d.Name))" />
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Publishers :</div>
|
||||
<MultipleSelectList TItem="PublisherDto" Theme="SelectListTheme" />
|
||||
<MultipleSelectList TItem="PublisherDto" Theme="SelectListTheme" @bind-Values=GameDto.Publishers
|
||||
Items="CategoriesDto?.Publishers?.Select(p => new SelectElement<PublisherDto>(p, p.Name))" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
@@ -35,15 +38,19 @@
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Properties :</div>
|
||||
<MultipleSelectList TItem="PropertyDto" Theme="SelectListTheme" />
|
||||
<MultipleSelectList TItem="PropertyDto" Theme="SelectListTheme" @bind-Values=GameDto.Properties
|
||||
Items="CategoriesDto?.Properties?.Select(p => new SelectElement<PropertyDto>(p, p.Label))" />
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Genres :</div>
|
||||
<MultipleSelectList TItem="TagDto" Theme="SelectListTheme" />
|
||||
<MultipleSelectList TItem="TagDto" Theme="SelectListTheme" @bind-Values=GameDto.Tags
|
||||
Items="CategoriesDto?.Tags?.Select(t => new SelectElement<TagDto>(t, t.Label))" />
|
||||
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Platforms :</div>
|
||||
<MultipleSelectList TItem="PlatformDto" Theme="SelectListTheme" />
|
||||
<MultipleSelectList TItem="PlatformDto" Theme="SelectListTheme" @bind-Values=GameDto.Platforms
|
||||
Items="CategoriesDto?.Platforms?.Select(p => new SelectElement<PlatformDto>(p, p.Label))" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -51,4 +58,12 @@
|
||||
<div id="label-description">@ResourcesKey.Description :</div>
|
||||
<input type="text" class="description" @bind-value=GameDto.Description>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button type="reset" class="cancel" @onclick=HandleOnCancel>
|
||||
@ResourcesKey.Reset
|
||||
</button>
|
||||
<button type="submit" class="submit">
|
||||
@ResourcesKey.Save
|
||||
</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
@@ -1,3 +1,4 @@
|
||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Slider;
|
||||
@@ -11,26 +12,45 @@ namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||
public partial class GameCreationForm
|
||||
{
|
||||
[Inject] private IJSRuntime Js { get; set; } = default!;
|
||||
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
||||
[CascadingParameter] private Popup? Popup { get; set; }
|
||||
|
||||
private GameDto GameDto = new();
|
||||
private CategoriesDto CategoriesDto = new();
|
||||
private EditContext? EditContext;
|
||||
private readonly SelectListTheme SelectListTheme = SelectListTheme.Creation;
|
||||
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
EditContext = new(GameDto);
|
||||
CategoriesDto = await GameGateway.FetchCategories();
|
||||
|
||||
if (Popup != null)
|
||||
{
|
||||
Popup.StateChanged += async (_, isOpen) => await HandlePopupStateChanged();
|
||||
}
|
||||
|
||||
base.OnInitialized();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private async Task HandlePopupStateChanged()
|
||||
{
|
||||
await Js.InvokeVoidAsync("resizeGameForm");
|
||||
}
|
||||
|
||||
private void HandleOnCancel()
|
||||
{
|
||||
Popup?.Close();
|
||||
}
|
||||
|
||||
private async Task HandleOnSubmit(EditContext args)
|
||||
{
|
||||
if (EditContext?.Validate() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,8 @@ input {
|
||||
.slider {
|
||||
padding: 0 20px;
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
input[type="number"]::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
@@ -5,13 +5,11 @@
|
||||
|
||||
<div class="duplicate">
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Plateforms"
|
||||
@bind-Values=GameFilterParams!.Platforms
|
||||
Placeholder="@ResourcesKey.Platforms"
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Genres"
|
||||
Placeholder="@ResourcesKey.Genres"
|
||||
@bind-Values=GameFilterParams!.Tags
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
@@ -19,31 +17,26 @@
|
||||
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Publishers"
|
||||
Placeholder="@ResourcesKey.Publishers"
|
||||
@bind-Values=GameFilterParams!.Publishers
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Developers"
|
||||
Placeholder="@ResourcesKey.Developers"
|
||||
@bind-Values=GameFilterParams!.Developers
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="StorageSizes"
|
||||
Placeholder="@ResourcesKey.StorageSize"
|
||||
@bind-Values=GameFilterParams!.StorageSizes
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="LastModifiedDates"
|
||||
Placeholder="@ResourcesKey.LastModification"
|
||||
@bind-Values=GameFilterParams!.LastModification
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="ReleaseDates"
|
||||
Placeholder="@ResourcesKey.ReleaseDate"
|
||||
@bind-Values=GameFilterParams!.ReleaseDates
|
||||
Theme="SelectListTheme.AdvancedFilter" />
|
||||
|
||||
@@ -7,56 +7,4 @@ public partial class AdvancedGameFilter
|
||||
{
|
||||
[Parameter] public GameFilterParams? GameFilterParams { get; set; }
|
||||
[Parameter] public EventCallback<GameFilterParams> GameFilterParamsChanged { get; set; }
|
||||
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Plateforms = [
|
||||
new() { Item = "Steam", Label = "Steam" },
|
||||
new() { Item = "GOG", Label = "GOG" },
|
||||
new() { Item = "Epic games", Label = "Epic games" },
|
||||
new() { Item = "Ubisoft", Label = "Ubisoft" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Genres = [
|
||||
new() { Item = "Rogue Like", Label = "Rogue Like" },
|
||||
new() { Item = "Aventure", Label = "Aventure" },
|
||||
new() { Item = "RPG", Label = "RPG" },
|
||||
new() { Item = "Fast FPS", Label = "Fast FPS" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Publishers = [
|
||||
new() { Item = "Electronic Arts", Label = "Electronic Arts" },
|
||||
new() { Item = "Ubisoft", Label = "Ubisoft" },
|
||||
new() { Item = "Activision Blizzard", Label = "Activision Blizzard" },
|
||||
new() { Item = "Bethesda", Label = "Bethesda" }
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Developers = [
|
||||
new() { Item = "CD Projekt Red", Label = "CD Projekt Red" },
|
||||
new() { Item = "Naughty Dog", Label = "Naughty Dog" },
|
||||
new() { Item = "Rockstar Games", Label = "Rockstar Games" },
|
||||
new() { Item = "FromSoftware", Label = "FromSoftware" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> StorageSizes = [
|
||||
new() { Item = "1 Go", Label = "1 Go" },
|
||||
new() { Item = "10 Go", Label = "10 Go" },
|
||||
new() { Item = "50 Go", Label = "50 Go" },
|
||||
new() { Item = "100 Go", Label = "100 Go" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> LastModifiedDates = [
|
||||
new() { Item = "2023-12-15", Label = "15 D<>cembre 2023" },
|
||||
new() { Item = "2024-01-20", Label = "20 Janvier 2024" },
|
||||
new() { Item = "2024-02-05", Label = "5 F<>vrier 2024" },
|
||||
new() { Item = "2024-03-10", Label = "10 Mars 2024" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> ReleaseDates = [
|
||||
new() { Item = "2023-11-11", Label = "11 Novembre 2023" },
|
||||
new() { Item = "2024-01-25", Label = "25 Janvier 2024" },
|
||||
new() { Item = "2024-03-03", Label = "3 Mars 2024" },
|
||||
new() { Item = "2024-04-15", Label = "15 Avril 2024" },
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
@@ -4,13 +4,13 @@
|
||||
@using GameIdeas.BlazorApp.Shared.Components.SliderRange
|
||||
@using GameIdeas.BlazorApp.Shared.Models
|
||||
@using GameIdeas.Shared.Dto
|
||||
@using GameIdeas.Shared.Enum
|
||||
|
||||
<div class="form-filter">
|
||||
<SelectList TItem="Func<GameDto, object>"
|
||||
Headers="SortTypes"
|
||||
Items="GameProperties"
|
||||
@bind-Value=GameFilterParams!.SortProperty
|
||||
HeaderChanged=HandleSortTypeChanged
|
||||
<SelectList TItem="Func<GameDto, object>" Items="GameProperties"
|
||||
@bind-Value=GameFilterParams.SortProperty
|
||||
THeader="SortType" Headers="SortTypes"
|
||||
@bind-Header=GameFilterParams.SortType
|
||||
Theme="SelectListTheme.Sort">
|
||||
<div class="square-button">
|
||||
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
<div class="select-container">
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Plateforms"
|
||||
Placeholder="@ResourcesKey.Platforms"
|
||||
@bind-Values=GameFilterParams.Platforms
|
||||
Theme="SelectListTheme.Filter" />
|
||||
@@ -46,7 +45,6 @@
|
||||
|
||||
<div class="select-container">
|
||||
<MultipleSelectList TItem="string"
|
||||
Items="Genres"
|
||||
Placeholder="@ResourcesKey.Genres"
|
||||
@bind-Values=GameFilterParams.Tags
|
||||
Theme="SelectListTheme.Filter" />
|
||||
|
||||
@@ -15,28 +15,14 @@ public partial class GameFilter
|
||||
[Parameter] public DisplayType DisplayType { get; set; }
|
||||
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
||||
|
||||
private readonly IEnumerable<SelectElement<Func<GameDto?, object?>>> SortTypes = [
|
||||
new() { Item = _ => SortType.Ascending, Label = "Ascendant", IsSelected = true },
|
||||
new() { Item = _ => SortType.Descending, Label = "Descendant" }
|
||||
private readonly IEnumerable<SelectElement<SortType>> SortTypes = [
|
||||
new(SortType.Ascending, "Ascendant") { IsSelected = true },
|
||||
new(SortType.Descending, "Descendant")
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<Func<GameDto?, object?>>> GameProperties = [
|
||||
new() { Item = game => game?.Title, Label = "Nom", IsSelected = true },
|
||||
new() { Item = game => game?.ReleaseDate, Label = "Date de parution" }
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Plateforms = [
|
||||
new() { Item = "Steam", Label = "Steam" },
|
||||
new() { Item = "GOG", Label = "GOG" },
|
||||
new() { Item = "Epic games", Label = "Epic games" },
|
||||
new() { Item = "Ubisoft", Label = "Ubisoft" },
|
||||
];
|
||||
|
||||
private readonly IEnumerable<SelectElement<string>> Genres = [
|
||||
new() { Item = "Rogue Like", Label = "Rogue Like" },
|
||||
new() { Item = "Aventure", Label = "Aventure" },
|
||||
new() { Item = "RPG", Label = "RPG" },
|
||||
new() { Item = "Fast FPS", Label = "Fast FPS" },
|
||||
new(game => game?.Title, "Nom") { IsSelected = true },
|
||||
new(game => game?.ReleaseDate, "Date de parution"),
|
||||
];
|
||||
|
||||
private EditContext? EditContext;
|
||||
@@ -52,11 +38,6 @@ public partial class GameFilter
|
||||
};
|
||||
}
|
||||
|
||||
private void HandleSortTypeChanged(Func<GameDto?, object?> getHeader)
|
||||
{
|
||||
GameFilterParams.SortType = (SortType?)getHeader(null) ?? SortType.Ascending;
|
||||
}
|
||||
|
||||
private async Task HandleDisplayClicked(DisplayType displayType)
|
||||
{
|
||||
DisplayType = displayType;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
|
||||
public class GameFilterParams
|
||||
{
|
||||
public SortType? SortType { get; set; }
|
||||
public SortType SortType { get; set; } = SortType.Ascending;
|
||||
public Func<GameDto?, object?>? SortProperty { get; set; }
|
||||
public string? SearchName { get; set; }
|
||||
public IEnumerable<string>? Platforms { get; set; }
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using GameIdeas.BlazorApp.Services;
|
||||
using GameIdeas.BlazorApp.Shared.Constants;
|
||||
using GameIdeas.BlazorApp.Shared.Exceptions;
|
||||
using GameIdeas.Resources;
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||
{
|
||||
public async Task<CategoriesDto> FetchCategories()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await httpClientService.FetchDataAsync<CategoriesDto>(Endpoints.Category.AllCategories);
|
||||
|
||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchCategories);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public interface IGameGateway
|
||||
{
|
||||
Task<CategoriesDto> FetchCategories();
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
</svg>
|
||||
</div>
|
||||
<SelectList @ref="SelectListAdd" TItem="AddType" Items="SelectElements"
|
||||
ValueChanged=HandleAddTypeClickedAsync
|
||||
ValueChanged=HandleAddTypeClickedAsync THeader="object"
|
||||
Theme="SelectListTheme.Navigation" AlignRight=true>
|
||||
<div class="second-button button">
|
||||
<svg class="button-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
|
||||
@@ -14,12 +14,12 @@ public partial class GameHeader : ComponentBase
|
||||
|
||||
|
||||
private readonly IEnumerable<SelectElement<AddType>> SelectElements = [
|
||||
new SelectElement<AddType> { Item = AddType.Manual, Label = ResourcesKey.ManualAdd },
|
||||
new SelectElement<AddType> { Item = AddType.Auto, Label = ResourcesKey.AutoAdd }
|
||||
new SelectElement<AddType>(AddType.Manual, ResourcesKey.ManualAdd),
|
||||
new SelectElement<AddType> (AddType.Auto, ResourcesKey.AutoAdd)
|
||||
];
|
||||
|
||||
private AccountSettings? AccountSettings;
|
||||
private SelectList<AddType>? SelectListAdd;
|
||||
private SelectList<AddType, object>? SelectListAdd;
|
||||
|
||||
private void HandleIconClicked()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Net.Http.Json;
|
||||
using GameIdeas.BlazorApp;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
using GameIdeas.BlazorApp.Services;
|
||||
using GameIdeas.Resources;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
@@ -22,7 +23,8 @@ builder.Services.AddHttpClient(
|
||||
client.Timeout = TimeSpan.FromMinutes(3);
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<AuthentificationService>();
|
||||
builder.Services.AddScoped<IHttpClientService, HttpClientService>();
|
||||
builder.Services.AddScoped<IGameGateway, GameGateway>();
|
||||
|
||||
builder.Services.AddSingleton<TranslationService>();
|
||||
builder.Services.AddSingleton<Translations>();
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace GameIdeas.BlazorApp.Services;
|
||||
|
||||
public class AuthentificationService
|
||||
{
|
||||
private bool isLogin;
|
||||
|
||||
public bool IsLogin
|
||||
{
|
||||
get { return isLogin; }
|
||||
}
|
||||
|
||||
public void Login()
|
||||
{
|
||||
isLogin = true;
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
isLogin = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using GameIdeas.Resources;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Services;
|
||||
|
||||
public class HttpClientService(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory) : IHttpClientService
|
||||
{
|
||||
private readonly HttpClient httpClient = httpClientFactory.CreateClient("GameIdeas.WebAPI");
|
||||
private readonly ILogger<HttpClientService> logger = loggerFactory.CreateLogger<HttpClientService>();
|
||||
|
||||
private readonly JsonSerializerOptions _optionsCamelCase = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
|
||||
};
|
||||
|
||||
private readonly JsonSerializerOptions _optionsCaseInsensitive = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
ReferenceHandler = ReferenceHandler.Preserve
|
||||
};
|
||||
|
||||
public async Task<T?> PostAsync<T>(string url, object data)
|
||||
{
|
||||
var jsonContent = JsonSerializer.Serialize(data, _optionsCamelCase);
|
||||
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
||||
var response = await httpClient.PostAsync(url, content);
|
||||
|
||||
return await GetResultValue<T>(response, ResourcesKey.ErrorWhenPostingData);
|
||||
}
|
||||
|
||||
public async Task<T?> PutAsync<T>(string url, object data)
|
||||
{
|
||||
var jsonContent = JsonSerializer.Serialize(data, _optionsCamelCase);
|
||||
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
||||
var response = await httpClient.PutAsync(url, content);
|
||||
|
||||
return await GetResultValue<T>(response, ResourcesKey.ErrorWhenPutingData);
|
||||
}
|
||||
|
||||
public async Task<T?> DeleteAsync<T>(string? url)
|
||||
{
|
||||
var response = await httpClient.DeleteAsync(url);
|
||||
|
||||
return await GetResultValue<T>(response, ResourcesKey.ErrorWhenDeletingData);
|
||||
}
|
||||
|
||||
public async Task<T?> FetchDataAsync<T>(string? url)
|
||||
{
|
||||
var response = await httpClient.GetAsync(url);
|
||||
|
||||
return await GetResultValue<T>(response, ResourcesKey.ErrorWhenFetchingData);
|
||||
}
|
||||
|
||||
public async Task<byte[]?> FetchBytesAsync(string? url)
|
||||
{
|
||||
var response = await httpClient.GetAsync(url);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsByteArrayAsync();
|
||||
}
|
||||
|
||||
throw new HttpRequestException(
|
||||
$"{ResourcesKey.ErrorWhenFetchingData} + StatusCode: {response.StatusCode} " +
|
||||
$"+ Reason: {response.ReasonPhrase}");
|
||||
}
|
||||
|
||||
public async Task<Stream?> FetchStreamAsync(string? url)
|
||||
{
|
||||
var response = await httpClient.GetAsync(url);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStreamAsync();
|
||||
}
|
||||
|
||||
throw new HttpRequestException($"{ResourcesKey.ErrorWhenFetchingData} + StatusCode: {response.StatusCode} " +
|
||||
$"+ Reason: {response.ReasonPhrase}");
|
||||
}
|
||||
|
||||
public async Task<T?> PostFileAsync<T>(string? url, Stream fileStream, string fileName, string contentType)
|
||||
{
|
||||
using var content = new MultipartFormDataContent();
|
||||
|
||||
var streamContent = new StreamContent(fileStream);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
||||
content.Add(streamContent, "file", fileName);
|
||||
|
||||
var response = await httpClient.PostAsync(url, content);
|
||||
|
||||
return await GetResultValue<T>(response, ResourcesKey.ErrorWhenPostingData);
|
||||
}
|
||||
|
||||
private async Task<T?> GetResultValue<T>(HttpResponseMessage response, string errorMessage)
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(responseContent))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
var result = JsonSerializer.Deserialize<T>(responseContent, _optionsCaseInsensitive);
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JsonException(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogError(ResourcesKey.RequestFailedStatusFormat, response.StatusCode);
|
||||
throw new HttpRequestException(
|
||||
$"{errorMessage} + StatusCode: {response.StatusCode} + Reason: {response.ReasonPhrase}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace GameIdeas.BlazorApp.Services;
|
||||
|
||||
public interface IHttpClientService
|
||||
{
|
||||
Task<T?> PostAsync<T>(string url, object data);
|
||||
Task<T?> PutAsync<T>(string url, object data);
|
||||
Task<T?> DeleteAsync<T>(string? url);
|
||||
Task<T?> FetchDataAsync<T>(string? url);
|
||||
Task<byte[]?> FetchBytesAsync(string? url);
|
||||
Task<Stream?> FetchStreamAsync(string? url);
|
||||
Task<T?> PostFileAsync<T>(string? url, Stream fileStream, string fileName, string contentType);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<div class="account-setting-container" tabindex="1000">
|
||||
<div class="account-setting-content @(ContentVisile ? string.Empty : "invisible")">
|
||||
@if (!AuthentificationService.IsLogin)
|
||||
@if (!IsLogin)
|
||||
{
|
||||
<EditForm EditContext="EditContext" OnSubmit="HandleLoginSubmit">
|
||||
<FluentValidationValidator />
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
using GameIdeas.BlazorApp.Services;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Shared.Components.Account;
|
||||
|
||||
public partial class AccountSettings (
|
||||
AuthentificationService AuthentificationService)
|
||||
public partial class AccountSettings
|
||||
{
|
||||
private bool ContentVisile = false;
|
||||
private EditContext? EditContext;
|
||||
private LoginDto LoginDto = new();
|
||||
private bool IsLoading = false;
|
||||
private bool IsLogin = true;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
EditContext = new EditContext(LoginDto);
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
ContentVisile = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
ContentVisile = false;
|
||||
@@ -45,15 +38,10 @@ public partial class AccountSettings (
|
||||
IsLoading = true;
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
Close();
|
||||
AuthentificationService.Login();
|
||||
IsLoading = false;
|
||||
|
||||
LoginDto = new();
|
||||
EditContext = new EditContext(LoginDto);
|
||||
}
|
||||
private void HandleLogoutClicked()
|
||||
{
|
||||
Close();
|
||||
AuthentificationService.Logout();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||
|
||||
public class SelectElement<TItem>
|
||||
public class SelectElement<TItem>(TItem item, string? label)
|
||||
{
|
||||
public TItem? Item { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public TItem Item { get; set; } = item;
|
||||
public string? Label { get; set; } = label;
|
||||
public bool IsSelected { get; set; } = false;
|
||||
public bool IsNew { get; set; } = false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@using GameIdeas.BlazorApp.Shared.Components.BackdropFilter
|
||||
@using GameIdeas.BlazorApp.Shared.Components.Select.Components
|
||||
@typeparam TItem
|
||||
@typeparam TItem
|
||||
@typeparam THeader
|
||||
|
||||
<div class="select-list">
|
||||
<div class="select-button" @onclick=HandleButtonClicked>
|
||||
@@ -11,10 +12,10 @@
|
||||
@if (IsContentOpen)
|
||||
{
|
||||
<div class="select-content @(Enum.GetName(Theme)?.ToLower())">
|
||||
@foreach (var item in Headers)
|
||||
@foreach (var header in Headers)
|
||||
{
|
||||
<SelectListElement TItem="TItem"
|
||||
Value="item"
|
||||
<SelectListElement TItem="THeader"
|
||||
Value="header"
|
||||
ValueChanged="HandleHeaderClicked"
|
||||
Theme="Theme" />
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Shared.Components.Select;
|
||||
|
||||
public partial class SelectList<TItem>
|
||||
public partial class SelectList<TItem, THeader>
|
||||
{
|
||||
[Parameter] public RenderFragment? ChildContent { get; set; }
|
||||
[Parameter] public TItem? Value { get; set; }
|
||||
[Parameter] public EventCallback<TItem?> ValueChanged { get; set; }
|
||||
[Parameter] public TItem? Header { get; set; }
|
||||
[Parameter] public EventCallback<TItem?> HeaderChanged { get; set; }
|
||||
[Parameter] public THeader? Header { get; set; }
|
||||
[Parameter] public EventCallback<THeader?> HeaderChanged { get; set; }
|
||||
[Parameter] public IEnumerable<SelectElement<TItem>> Items { get; set; } = [];
|
||||
[Parameter] public IEnumerable<SelectElement<TItem>> Headers { get; set; } = [];
|
||||
[Parameter] public IEnumerable<SelectElement<THeader>> Headers { get; set; } = [];
|
||||
[Parameter] public SelectListTheme Theme { get; set; }
|
||||
[Parameter] public bool AlignRight { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public partial class SelectList<TItem>
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
|
||||
private async Task HandleHeaderClicked(SelectElement<TItem> selectedValue)
|
||||
private async Task HandleHeaderClicked(SelectElement<THeader> selectedValue)
|
||||
{
|
||||
foreach (var header in Headers)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace GameIdeas.BlazorApp.Shared.Constants;
|
||||
|
||||
public static class Endpoints
|
||||
{
|
||||
public static class Game
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static class Category
|
||||
{
|
||||
public static readonly string AllCategories = "api/Category/All";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||
|
||||
public class CategoryNotFoundException(string message) : Exception(message);
|
||||
Reference in New Issue
Block a user