Create game
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 46s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 46s
This commit is contained in:
@@ -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="container">
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div id="first-label" class="label">@ResourcesKey.Title :</div>
|
<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>
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using GameIdeas.BlazorApp.Helpers;
|
||||||
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.Components.Select.Models;
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
@@ -20,7 +21,7 @@ public partial class GameCreationForm
|
|||||||
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 };
|
||||||
private bool IsLoading = true;
|
private bool IsLoading = false;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@@ -46,10 +47,25 @@ public partial class GameCreationForm
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
IsLoading = true;
|
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;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,11 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|||||||
|
|
||||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||||
{
|
{
|
||||||
public async Task<GameDto> CreateGame(GameDto game)
|
public async Task<int> CreateGame(GameDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await httpClientService.PostAsync<GameDto>(Endpoints.Game.Create, game);
|
return await httpClientService.PostAsync<int>(Endpoints.Game.Create, game);
|
||||||
|
|
||||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame);
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|||||||
public interface IGameGateway
|
public interface IGameGateway
|
||||||
{
|
{
|
||||||
Task<CategoriesDto> FetchCategories();
|
Task<CategoriesDto> FetchCategories();
|
||||||
Task<GameDto> CreateGame(GameDto game);
|
Task<int> CreateGame(GameDto game);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
height: 20px;
|
height: 20px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.select-element:hover {
|
.select-element:hover {
|
||||||
cursor: pointer;
|
|
||||||
background: var(--input-selected);
|
background: var(--input-selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
z-index: var(--index-component)
|
z-index: var(--index-component);
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown {
|
.dropdown {
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("Create")]
|
[HttpPost("Create")]
|
||||||
public async Task<ActionResult<GameDto>> CreateGame([FromBody] GameDto game)
|
public async Task<ActionResult<int>> CreateGame([FromBody] GameDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Created("/Create", await gameService.CreateGame(game));
|
var gameResult = await gameService.CreateGame(game);
|
||||||
|
return Created("/Create", gameResult.Id);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -54,11 +55,12 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("Update")]
|
[HttpPut("Update")]
|
||||||
public async Task<ActionResult<GameDto>> UpdateGame([FromBody] GameDto game)
|
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDto game)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Created($"/Update", await gameService.UpdateGame(game));
|
var gameResult = await gameService.UpdateGame(game);
|
||||||
|
return Created($"/Update", gameResult.Id);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user