Create game from form #15
@@ -0,0 +1,12 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Helpers;
|
||||
|
||||
public static class GameHelper
|
||||
{
|
||||
public static void WriteTrackingDto(GameDto game)
|
||||
{
|
||||
game.CreationUserId = 100000;
|
||||
game.CreationDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="container">
|
||||
<div class="input-game">
|
||||
<div id="first-label" class="label">@ResourcesKey.Title :</div>
|
||||
<InputText class="title" @bind-Value=GameDto.Title />
|
||||
<InputText class="title" @bind-Value=GameDto.Title/>
|
||||
</div>
|
||||
<div class="input-game">
|
||||
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using GameIdeas.BlazorApp.Helpers;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||
@@ -20,7 +21,7 @@ public partial class GameCreationForm
|
||||
private EditContext? EditContext;
|
||||
private readonly SelectTheme Theme = SelectTheme.Creation;
|
||||
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
|
||||
private bool IsLoading = true;
|
||||
private bool IsLoading = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -46,10 +47,25 @@ public partial class GameCreationForm
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
await GameGateway.CreateGame(GameDto);
|
||||
GameHelper.WriteTrackingDto(GameDto);
|
||||
var gameId = await GameGateway.CreateGame(GameDto);
|
||||
|
||||
if (gameId != 0)
|
||||
{
|
||||
Popup?.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,11 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||
{
|
||||
public async Task<GameDto> CreateGame(GameDto game)
|
||||
public async Task<int> CreateGame(GameDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await httpClientService.PostAsync<GameDto>(Endpoints.Game.Create, game);
|
||||
|
||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame);
|
||||
return await httpClientService.PostAsync<int>(Endpoints.Game.Create, game);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
public interface IGameGateway
|
||||
{
|
||||
Task<CategoriesDto> FetchCategories();
|
||||
Task<GameDto> CreateGame(GameDto game);
|
||||
Task<int> CreateGame(GameDto game);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
height: 20px;
|
||||
align-items: center;
|
||||
padding: 2px 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.select-element:hover {
|
||||
cursor: pointer;
|
||||
background: var(--input-selected);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
}
|
||||
|
||||
.button {
|
||||
z-index: var(--index-component)
|
||||
z-index: var(--index-component);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
|
||||
@@ -40,11 +40,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
}
|
||||
|
||||
[HttpPost("Create")]
|
||||
public async Task<ActionResult<GameDto>> CreateGame([FromBody] GameDto game)
|
||||
public async Task<ActionResult<int>> CreateGame([FromBody] GameDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Created("/Create", await gameService.CreateGame(game));
|
||||
var gameResult = await gameService.CreateGame(game);
|
||||
return Created("/Create", gameResult.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -54,11 +55,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
}
|
||||
|
||||
[HttpPut("Update")]
|
||||
public async Task<ActionResult<GameDto>> UpdateGame([FromBody] GameDto game)
|
||||
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Created($"/Update", await gameService.UpdateGame(game));
|
||||
var gameResult = await gameService.UpdateGame(game);
|
||||
return Created($"/Update", gameResult.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user