Add frontend creation game (#13)
Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GameIdeas.WebAPI.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CategoryController(ICategoryService categoryService, ILoggerFactory loggerFactory) : Controller
|
||||
{
|
||||
private readonly ILogger<CategoryController> logger = loggerFactory.CreateLogger<CategoryController>();
|
||||
|
||||
[HttpGet("All")]
|
||||
public async Task<ActionResult<CategoriesDto>> FetchAllCategories()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await categoryService.GetCategories());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Internal error while fetching categories");
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.WebAPI.Services;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GameIdeas.WebAPI.Controllers;
|
||||
@@ -7,7 +7,7 @@ namespace GameIdeas.WebAPI.Controllers;
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
|
||||
public class GameController(GameService gameService, ILoggerFactory loggerFactory) : Controller
|
||||
public class GameController(IGameService gameService, ILoggerFactory loggerFactory) : Controller
|
||||
{
|
||||
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
||||
|
||||
|
||||
@@ -14,7 +14,20 @@
|
||||
"Genres": "Genres",
|
||||
"Publishers": "Editeurs",
|
||||
"Developers": "Développeurs",
|
||||
"StorageSizes": "Taille d'espace",
|
||||
"StorageSize": "Taille d'espace",
|
||||
"StorageSizeMo": "Taille d'espace en Mo",
|
||||
"LastModification": "Dernière modifications",
|
||||
"ReleaseDates": "Dates de parution"
|
||||
"ReleaseDate": "Date de parution",
|
||||
"Title": "Titre",
|
||||
"Interest": "Intérêt",
|
||||
"Properties": "Propriétés",
|
||||
"Description": "Description",
|
||||
"Save": "Enregister",
|
||||
"Reset": "Annuler",
|
||||
"ErrorWhenPostingData": "Erreur lors de la requête POST",
|
||||
"ErrorWhenPutingData": "Erreur lors de la requête PUT",
|
||||
"ErrorWhenDeletingData": "Erreur lors de la requête DELETE",
|
||||
"ErrorWhenFetchingData": "Erreur lors de la requête GET",
|
||||
"RequestFailedStatusFormat": "Erreur lors de la réponse, code {0}",
|
||||
"ErrorFetchCategories": "Erreur lors de la récupération des catégories"
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using GameIdeas.Resources;
|
||||
using GameIdeas.WebAPI.Context;
|
||||
using GameIdeas.WebAPI.Profiles;
|
||||
using GameIdeas.WebAPI.Services;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -31,11 +32,10 @@ services.AddDbContext<GameIdeasContext>(dbContextOptions);
|
||||
services.AddSingleton<TranslationService>();
|
||||
services.AddSingleton<Translations>();
|
||||
|
||||
services.AddScoped<GameService>();
|
||||
services.AddScoped<IGameService, GameService>();
|
||||
services.AddScoped<ICategoryService, CategoryService>();
|
||||
|
||||
services.AddAutoMapper(typeof(GameProfile).Assembly);
|
||||
services.AddAutoMapper(typeof(UserProfile).Assembly);
|
||||
services.AddAutoMapper(typeof(CategoryProfile).Assembly);
|
||||
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using AutoMapper;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.WebAPI.Context;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GameIdeas.WebAPI.Services;
|
||||
|
||||
public class CategoryService(GameIdeasContext context, IMapper mapper) : ICategoryService
|
||||
{
|
||||
public async Task<CategoriesDto> GetCategories()
|
||||
{
|
||||
var platforms = await context.Platforms.ToListAsync();
|
||||
var properties = await context.Properties.ToListAsync();
|
||||
var tags = await context.Tags.ToListAsync();
|
||||
var developers = await context.Developers.ToListAsync();
|
||||
var publishers = await context.Publishers.ToListAsync();
|
||||
|
||||
return new()
|
||||
{
|
||||
Platforms = mapper.Map<IEnumerable<PlatformDto>>(platforms),
|
||||
Properties = mapper.Map<IEnumerable<PropertyDto>>(properties),
|
||||
Tags = mapper.Map<IEnumerable<TagDto>>(tags),
|
||||
Developers = mapper.Map<IEnumerable<DeveloperDto>>(developers),
|
||||
Publishers = mapper.Map<IEnumerable<PublisherDto>>(publishers)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@ using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.Shared.Exceptions;
|
||||
using GameIdeas.Shared.Model;
|
||||
using GameIdeas.WebAPI.Context;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GameIdeas.WebAPI.Services;
|
||||
|
||||
public class GameService(GameIdeasContext context, IMapper mapper)
|
||||
public class GameService(GameIdeasContext context, IMapper mapper) : IGameService
|
||||
{
|
||||
public async Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.WebAPI.Services.Interfaces;
|
||||
|
||||
public interface ICategoryService
|
||||
{
|
||||
Task<CategoriesDto> GetCategories();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.WebAPI.Services.Interfaces;
|
||||
|
||||
public interface IGameService
|
||||
{
|
||||
Task<IEnumerable<GameDto>> GetGames(PaggingDto pagging);
|
||||
Task<GameDto> GetGameById(int gameId);
|
||||
Task<GameDto> CreateGame(GameDto gameDto);
|
||||
Task<GameDto> UpdateGame(GameDto gameDto);
|
||||
Task<bool> DeleteGame(int gameId);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace GameIdeas.WebAPI.Services;
|
||||
|
||||
public class UserService
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user