mise a jour route
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
parent a263050ab6
commit ff3a1a0efa

@ -8,7 +8,7 @@ using Shared;
namespace Contextlib namespace Contextlib
{ {
internal class DbSourceManager : ISourceService<Source> public class DbSourceManager : ISourceService<Source>
{ {
private WTFContext _context; private WTFContext _context;
private GenericRepository<Source> _repo; private GenericRepository<Source> _repo;

@ -1,12 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Shared namespace Shared
{ {
public interface IFavoriteService public interface IFavoriteService<TQuote>
{ {
// Adds a quote to a user's list of favorites. // Adds a quote to a user's list of favorites.
// 'quoteid' is the unique identifier of the quote to be added to favorites. // 'quoteid' is the unique identifier of the quote to be added to favorites.
@ -25,5 +26,8 @@ namespace Shared
// Removes a specific quote from the favorite lists of all users. // Removes a specific quote from the favorite lists of all users.
// 'quoteId' is the unique identifier of the quote to be removed from all users' favorites. // 'quoteId' is the unique identifier of the quote to be removed from all users' favorites.
Task RemoveAllFavoriteForQuote(int quoteId); Task RemoveAllFavoriteForQuote(int quoteId);
Task<PaginationResult<TQuote>> GetFavoriteByIdUser(int userId, int index, int count);
Task<TQuote> GetFavorite(int userId, int idQuote);
} }
} }

@ -127,11 +127,11 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entity.Commentary", b => modelBuilder.Entity("Entity.Commentary", b =>
{ {
b.Property<int>("IdUser") b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("IdQuote") SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
.HasColumnType("int");
b.Property<string>("Comment") b.Property<string>("Comment")
.IsRequired() .IsRequired()
@ -142,34 +142,36 @@ namespace StubbedContextLib.Migrations
.HasColumnType("date") .HasColumnType("date")
.HasColumnName("DateCommentary"); .HasColumnName("DateCommentary");
b.Property<int>("Id") b.Property<int>("IdQuote")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); b.Property<int>("IdUser")
.HasColumnType("int");
b.HasKey("IdUser", "IdQuote"); b.HasKey("Id");
b.HasIndex("IdQuote"); b.HasIndex("IdQuote");
b.HasIndex("IdUser");
b.ToTable("comments"); b.ToTable("comments");
b.HasData( b.HasData(
new new
{ {
IdUser = 2, Id = 1,
IdQuote = 1,
Comment = "Ce film est le meilleur", Comment = "Ce film est le meilleur",
DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 1 IdQuote = 1,
IdUser = 2
}, },
new new
{ {
IdUser = 3, Id = 2,
IdQuote = 1,
Comment = "Very good", Comment = "Very good",
DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 2 IdQuote = 1,
IdUser = 3
}); });
}); });

@ -0,0 +1,125 @@
using System.Net;
using DTO;
using Entity;
using Microsoft.AspNetCore.Mvc;
using ServicesApi;
using Shared;
namespace WfApi.Controllers
{
[ApiController]
[Route("api/v1/favorite")] //Version API
public class FavoriteControleur : ControllerBase
{
private readonly IFavoriteService<QuoteDTO> _favorite;
private readonly ILogger<FavoriteControleur> _logger;
public FavoriteControleur(IFavoriteService<QuoteDTO> favoriteService, ILogger<FavoriteControleur> logger)
{
_favorite = favoriteService;
_logger = logger;
}
[HttpGet("{id}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetFavoriteByIdUser(int id, int index = 0, int count = 10)
{
try
{
var result = await _favorite.GetFavoriteByIdUser(id, index, count);
if (result != null)
{
return await Task.FromResult<IActionResult>(Ok(result));
}
else
{
return NoContent();
}
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateFavorite(int idUser , int idQuote)
{
try
{
var existingFavorite = _favorite.GetFavorite(idUser,idQuote).Result;
if (existingFavorite != null)
{
return Conflict(new { message = "A favorite with this ID already exists." });
}
await _favorite.AddFavorite(idUser, idQuote);
var fav = new Favorite();
fav.IdQuote = idQuote;
fav.IdUsers = idUser;
return CreatedAtAction(nameof(GetFavoriteByIdUser), new { id = idUser }, fav);
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." });
}
}
[HttpDelete] // /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)
{
try
{
var existingFavorite = await _favorite.GetFavorite(idUser, idQuote);
if (existingFavorite == null)
{
return NotFound(new { message = "Commentary not found." });
}
await _favorite.RemoveFavorite(idUser, idQuote);
return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." });
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
}
[HttpDelete] // /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)
{
try
{
var existingFavorite = await _favorite.GetFavorite(idUser, idQuote);
if (existingFavorite == null)
{
return NotFound(new { message = "Commentary not found." });
}
await _favorite.RemoveFavorite(idUser, idQuote);
return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." });
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
}
}
}

@ -15,7 +15,7 @@ builder.Services.AddScoped<IQuoteService<QuoteDTO>, QuoteService>();
builder.Services.AddScoped<ICommentaryService<CommentaryDTO>, CommentaryService>(); builder.Services.AddScoped<ICommentaryService<CommentaryDTO>, CommentaryService>();
builder.Services.AddScoped<ICharacterService<CharacterDTO>, CharacterService>(); builder.Services.AddScoped<ICharacterService<CharacterDTO>, CharacterService>();
builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>(); builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>();
//builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>(); builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>(); builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>();
@ -28,7 +28,7 @@ builder.Services.AddScoped<IQuoteService<Quote>, DbQuoteManager>();
builder.Services.AddScoped<ICommentaryService<Commentary>, DbCommentaryManager>(); builder.Services.AddScoped<ICommentaryService<Commentary>, DbCommentaryManager>();
builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>(); builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>();
builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>(); builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>();
//builder.Services.AddScoped<ISourceService<Source>, DbSourceManager>(); builder.Services.AddScoped<ISourceService<Source>, DbSourceManager>();
builder.Services.AddScoped<IQuestionService<Question>, DbQuestionManager>(); builder.Services.AddScoped<IQuestionService<Question>, DbQuestionManager>();
//... //...

Loading…
Cancel
Save