diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs index 314da25..27e1b90 100644 --- a/WF_EF_Api/Contextlib/DbFavoriteManager.cs +++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Contextlib { - public class DbFavoriteManager : IFavoriteService + public class DbFavoriteManager : IFavoriteService { private WTFContext _context; @@ -22,6 +22,7 @@ namespace Contextlib throw new NotImplementedException(); } + public async Task RemoveAllFavoriteForQuote(int quoteId) { throw new NotImplementedException(); @@ -36,5 +37,15 @@ namespace Contextlib { throw new NotImplementedException(); } + + public Task GetFavorite(int userId, int idQuote) + { + throw new NotImplementedException(); + } + + public Task> GetFavoriteByIdUser(int userId, int index, int count) + { + throw new NotImplementedException(); + } } } diff --git a/WF_EF_Api/ServicesApi/FavoriteService.cs b/WF_EF_Api/ServicesApi/FavoriteService.cs index d3b3802..a2a0030 100644 --- a/WF_EF_Api/ServicesApi/FavoriteService.cs +++ b/WF_EF_Api/ServicesApi/FavoriteService.cs @@ -8,15 +8,16 @@ using Entity; using Shared; using Dto2Entities; using static System.Net.Mime.MediaTypeNames; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace ServicesApi { - public class FavoriteService : IFavoriteService + public class FavoriteService : IFavoriteService { - private IFavoriteService favoriteService; + private IFavoriteService favoriteService; - public FavoriteService(IFavoriteService favorite) + public FavoriteService(IFavoriteService favorite) { favoriteService = favorite; } @@ -41,5 +42,17 @@ namespace ServicesApi { await favoriteService.RemoveFavorite(quoteid, userId); } + + public async Task GetFavorite(int userId, int idQuote) + { + return (await favoriteService.GetFavorite(userId,idQuote) ).ToDto(); + } + + public async Task> GetFavoriteByIdUser(int userId, int index, int count) + { + var fav = (await favoriteService.GetFavoriteByIdUser(userId, index, count)).items; + return new PaginationResult(fav.Count(), 0, 10, fav.ToDto()); + + } } } diff --git a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs index 2529717..7ef8a7c 100644 --- a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs +++ b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs @@ -85,7 +85,7 @@ namespace WfApi.Controllers var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); if (existingFavorite == null) { - return NotFound(new { message = "Commentary not found." }); + return NotFound(new { message = "Favorite not found." }); } await _favorite.RemoveFavorite(idUser, idQuote); @@ -97,24 +97,36 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); } } - [HttpDelete] // /api/v1/commentary?id=51 + [HttpDelete("alluser")] // /api/v1/commentary?id=51 [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task DeleteFavorite([FromQuery] int idUser, [FromQuery] int idQuote) + public async Task DeleteAllFavoriteForUser([FromQuery] int idUser) { try { - var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); - if (existingFavorite == null) - { - return NotFound(new { message = "Commentary not found." }); - } + await _favorite.RemoveAllFavoriteForUser(idUser); - await _favorite.RemoveFavorite(idUser, idQuote); + return Ok(new { message = $"Favorite from user {idUser} deleted successfully." }); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + [HttpDelete("allquote")] // /api/v1/commentary?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteAllFavoriteForQuote([FromQuery] int idQuote) + { + try + { - return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." }); + await _favorite.RemoveAllFavoriteForQuote(idQuote); + + return Ok(new { message = $"Favorite from quote {idQuote} deleted successfully." }); } catch (Exception) { diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 6d308be..24338f1 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -12,6 +12,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddScoped, UserService>(); builder.Services.AddScoped, QuoteService>(); +builder.Services.AddScoped, FavoriteService>(); builder.Services.AddScoped, CommentaryService>(); builder.Services.AddScoped, CharacterService>(); builder.Services.AddScoped, ImageService>();