correction erreur favorite
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
parent ff3a1a0efa
commit 831a65f244

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Contextlib
{
public class DbFavoriteManager : IFavoriteService
public class DbFavoriteManager : IFavoriteService<Quote>
{
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<Quote> GetFavorite(int userId, int idQuote)
{
throw new NotImplementedException();
}
public Task<PaginationResult<Quote>> GetFavoriteByIdUser(int userId, int index, int count)
{
throw new NotImplementedException();
}
}
}

@ -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<QuoteDTO>
{
private IFavoriteService favoriteService;
private IFavoriteService<Quote> favoriteService;
public FavoriteService(IFavoriteService favorite)
public FavoriteService(IFavoriteService<Quote> favorite)
{
favoriteService = favorite;
}
@ -41,5 +42,17 @@ namespace ServicesApi
{
await favoriteService.RemoveFavorite(quoteid, userId);
}
public async Task<QuoteDTO> GetFavorite(int userId, int idQuote)
{
return (await favoriteService.GetFavorite(userId,idQuote) ).ToDto();
}
public async Task<PaginationResult<QuoteDTO>> GetFavoriteByIdUser(int userId, int index, int count)
{
var fav = (await favoriteService.GetFavoriteByIdUser(userId, index, count)).items;
return new PaginationResult<QuoteDTO>(fav.Count(), 0, 10, fav.ToDto());
}
}
}

@ -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<IActionResult> DeleteFavorite([FromQuery] int idUser, [FromQuery] int idQuote)
public async Task<IActionResult> 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<IActionResult> 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)
{

@ -12,6 +12,7 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IUserService<UserDTO>, UserService>();
builder.Services.AddScoped<IQuoteService<QuoteDTO>, QuoteService>();
builder.Services.AddScoped<IFavoriteService<QuoteDTO>, FavoriteService>();
builder.Services.AddScoped<ICommentaryService<CommentaryDTO>, CommentaryService>();
builder.Services.AddScoped<ICharacterService<CharacterDTO>, CharacterService>();
builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>();

Loading…
Cancel
Save