Add validation and gateway creation
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 1m14s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 1m14s
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
@using GameIdeas.BlazorApp.Shared.Components.SelectSearch
|
||||
@using Blazored.FluentValidation
|
||||
@using GameIdeas.BlazorApp.Shared.Components.SelectSearch
|
||||
@using GameIdeas.BlazorApp.Shared.Components.Slider
|
||||
@using GameIdeas.Shared.Dto
|
||||
|
||||
<EditForm EditContext="EditContext" OnSubmit="HandleOnSubmit">
|
||||
<FluentValidationValidator/>
|
||||
<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" @bind=GameDto.Title>
|
||||
<InputText class="title" @bind-Value=GameDto.Title />
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
||||
<input type="date" class="date" @bind=GameDto.ReleaseDate>
|
||||
<InputDate TValue="DateTime?" class="date" @bind-Value=GameDto.ReleaseDate />
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.StorageSizeMo :</div>
|
||||
<input type="number" class="storage" @bind=GameDto.StorageSpace>
|
||||
<InputNumber TValue="double?" class="storage" @bind-Value=GameDto.StorageSpace />
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.Developers :</div>
|
||||
@@ -61,14 +63,14 @@
|
||||
{
|
||||
<div class="input-game">
|
||||
<div class="label">@platform.Label :</div>
|
||||
<input type="text" class="url" @bind=platform.Url>
|
||||
<InputText class="url" @bind-Value=platform.Url />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="description-container">
|
||||
<div id="label-description">@ResourcesKey.Description :</div>
|
||||
<input type="text" class="description" @bind-value=GameDto.Description>
|
||||
<InputTextArea class="description" @bind-Value=GameDto.Description />
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button type="reset" class="cancel" @onclick=HandleOnCancel>
|
||||
|
||||
@@ -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,6 +12,7 @@ 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; }
|
||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||
|
||||
@@ -48,6 +50,6 @@ public partial class GameCreationForm
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await GameGateway.CreateGame(GameDto);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
grid-column: 1;
|
||||
}
|
||||
|
||||
input {
|
||||
::deep input, ::deep textarea {
|
||||
width: 100%;
|
||||
background: var(--input-secondary);
|
||||
border: solid 1px var(--input-selected);
|
||||
@@ -35,11 +35,16 @@ input {
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
input[type="date"]::-webkit-calendar-picker-indicator {
|
||||
::deep input[type="date"]::-webkit-calendar-picker-indicator {
|
||||
filter: invert(1);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::deep textarea {
|
||||
resize: vertical;
|
||||
min-height: 140px;
|
||||
}
|
||||
|
||||
.description-container {
|
||||
margin-top: 8px;
|
||||
display: grid;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using FluentValidation;
|
||||
using GameIdeas.Shared.Constants;
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||
|
||||
public class GameValidation : AbstractValidator<GameDto>
|
||||
{
|
||||
public GameValidation()
|
||||
{
|
||||
RuleFor(g => g.Title)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.Matches(GlobalConstants.RegexName);
|
||||
|
||||
RuleFor(g => g.ReleaseDate)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
|
||||
RuleFor(g => g.Interest)
|
||||
.NotNull()
|
||||
.GreaterThanOrEqualTo(1)
|
||||
.LessThanOrEqualTo(5);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,20 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||
{
|
||||
public async Task<GameDto> CreateGame(GameDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await httpClientService.PostAsync<GameDto>(Endpoints.Game.Create, game);
|
||||
|
||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new GameCreationException(ResourcesKey.ErrorCreateGame);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CategoriesDto> FetchCategories()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
public interface IGameGateway
|
||||
{
|
||||
Task<CategoriesDto> FetchCategories();
|
||||
Task<GameDto> CreateGame(GameDto game);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user