feature/apply-filter #18
@@ -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;
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|||||||
@@ -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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ 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(PaggingDto pagging);
|
||||||
}
|
}
|
||||||
|
|||||||
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; }
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public class SortPropertyDto
|
public class SortPropertyDto
|
||||||
{
|
{
|
||||||
public Func<GameDto, object>? SortProperty { get; set; }
|
public Func<GameDetailDto, object>? SortProperty { get; set; }
|
||||||
public string Label { get; set; } = string.Empty;
|
public string Label { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
|||||||
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] PaggingDto pagging)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,7 @@ 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
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,7 @@ 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
|
||||||
{
|
{
|
||||||
@@ -55,7 +55,7 @@ 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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,17 +21,17 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
|
|||||||
return mapper.Map<IEnumerable<GameDto>>(games);
|
return mapper.Map<IEnumerable<GameDto>>(games);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GameDto> GetGameById(int gameId)
|
public async Task<GameDetailDto> GetGameById(int gameId)
|
||||||
{
|
{
|
||||||
var game = await SelectGames()
|
var game = await SelectGames()
|
||||||
.FirstOrDefaultAsync(g => g.Id == gameId);
|
.FirstOrDefaultAsync(g => g.Id == gameId);
|
||||||
|
|
||||||
return game == null
|
return game == null
|
||||||
? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context")
|
? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context")
|
||||||
: mapper.Map<GameDto>(game);
|
: mapper.Map<GameDetailDto>(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GameDto> CreateGame(GameDto gameDto)
|
public async Task<GameDetailDto> CreateGame(GameDetailDto gameDto)
|
||||||
{
|
{
|
||||||
var gameToCreate = mapper.Map<Game>(gameDto);
|
var gameToCreate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
@@ -46,10 +46,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 +67,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)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace GameIdeas.WebAPI.Services.Interfaces;
|
|||||||
public interface IGameService
|
public interface IGameService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging);
|
Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging);
|
||||||
Task<GameDto> GetGameById(int gameId);
|
Task<GameDetailDto> GetGameById(int gameId);
|
||||||
Task<GameDto> CreateGame(GameDto gameDto);
|
Task<GameDetailDto> CreateGame(GameDetailDto gameDto);
|
||||||
Task<GameDto> UpdateGame(GameDto gameDto);
|
Task<GameDetailDto> UpdateGame(GameDetailDto gameDto);
|
||||||
Task<bool> DeleteGame(int gameId);
|
Task<bool> DeleteGame(int gameId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user