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
{
internal class DbSourceManager : ISourceService<Source>
public class DbSourceManager : ISourceService<Source>
{
private WTFContext _context;
private GenericRepository<Source> _repo;

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Shared
{
public interface IFavoriteService
public interface IFavoriteService<TQuote>
{
// Adds a quote to a user's list of 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.
// 'quoteId' is the unique identifier of the quote to be removed from all users' favorites.
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 =>
{
b.Property<int>("IdUser")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("IdQuote")
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Comment")
.IsRequired()
@ -142,34 +142,36 @@ namespace StubbedContextLib.Migrations
.HasColumnType("date")
.HasColumnName("DateCommentary");
b.Property<int>("Id")
.ValueGeneratedOnAdd()
b.Property<int>("IdQuote")
.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("IdUser");
b.ToTable("comments");
b.HasData(
new
{
IdUser = 2,
IdQuote = 1,
Id = 1,
Comment = "Ce film est le meilleur",
DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 1
IdQuote = 1,
IdUser = 2
},
new
{
IdUser = 3,
IdQuote = 1,
Id = 2,
Comment = "Very good",
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<ICharacterService<CharacterDTO>, CharacterService>();
builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>();
//builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
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<ICharacterService<Character>, DbCharacterManager>();
builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>();
//builder.Services.AddScoped<ISourceService<Source>, DbSourceManager>();
builder.Services.AddScoped<ISourceService<Source>, DbSourceManager>();
builder.Services.AddScoped<IQuestionService<Question>, DbQuestionManager>();
//...

Loading…
Cancel
Save