Merge branch 'Merge_API_EF' of https://codefirst.iut.uca.fr/git/WhatTheFantasy/WF-PmAPI into Merge_API_EF
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
commit 5b01d086ad

@ -8,6 +8,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
</ItemGroup>

@ -27,13 +27,30 @@ namespace Contextlib
/// <param name="comment">The comment to add.</param>
/// <returns>A task representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">Thrown when the comment is null.</exception>
public async Task AddComment(Commentary comment)
public async Task AddComment(Commentary comment, int idQuote)
{
if (comment == null)
{
throw new ArgumentNullException(nameof(comment), "Comment cannot be null.");
}
var quote = await _context.quotes
.Include(q => q.Commentarys) // collection des commentaires est chargée
.FirstOrDefaultAsync(q => q.Id == idQuote);
if (quote == null)
{
throw new ArgumentException("Quote not exist", nameof(idQuote));
}
// Lien entre le commentaire et la citation
comment.Quote = quote;
comment.IdQuote = idQuote;
// Ajout commentaire à la collection des commentaires de la citation
quote.Commentarys.Add(comment);
_repo.Insert(comment);
await _context.SaveChangesAsync();
}

@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -6,6 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Entity\Entity.csproj" />

@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using Entity;
using Shared;
using Dto2Entities;
namespace ServicesApi
{
public class CharacterService : ICharacterService<CharacterDTO>
{
private ICharacterService<Character> characterService;
public CharacterService(ICharacterService<Character> character)
{
characterService = character;
}
public async Task AddCharacter(CharacterDTO character)
{
await characterService.AddCharacter(character.ToEntity());
}
public async Task<PaginationResult<CharacterDTO>> GetAll()
{
var characters = characterService.GetAll().Result.items;
return new PaginationResult<CharacterDTO>(characters.Count(), 0, 10, characters.ToDto());
}
public async Task<CharacterDTO> GetCharById(int id)
{
return characterService.GetCharById(id).Result.ToDto();
}
public async Task<CharacterDTO> GetCharByName(string name)
{
return characterService.GetCharByName(name).Result.ToDto();
}
public async Task<int> GetLastCharId()
{
return await characterService.GetLastCharId();
}
public async Task RemoveCharacter(int id)
{
await characterService.RemoveCharacter(id);
}
public async Task UpdateCharacter(int id, CharacterDTO character)
{
await characterService.UpdateCharacter(id, character.ToEntity());
}
}
}

@ -19,9 +19,9 @@ namespace ServicesApi
commentaryService = commentary;
}
public async Task AddComment(CommentaryDTO commentary)
public async Task AddComment(CommentaryDTO commentary, int idQuote)
{
await commentaryService.AddComment(commentary.ToEntity());
await commentaryService.AddComment(commentary.ToEntity(), idQuote);
}
public async Task DeleteCommentaryForQuote(int quoteId)

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using Entity;
using Shared;
using Dto2Entities;
using static System.Net.Mime.MediaTypeNames;
namespace ServicesApi
{
public class FavoriteService : IFavoriteService
{
private IFavoriteService favoriteService;
public FavoriteService(IFavoriteService favorite)
{
favoriteService = favorite;
}
public async Task AddFavorite(int quoteid, int userId)
{
await favoriteService.AddFavorite(quoteid, userId);
}
public async Task RemoveAllFavoriteForQuote(int quoteId)
{
await favoriteService.RemoveAllFavoriteForQuote(quoteId);
}
public async Task RemoveAllFavoriteForUser(int userId)
{
await favoriteService.RemoveAllFavoriteForUser(userId);
}
public async Task RemoveFavorite(int quoteid, int userId)
{
await favoriteService.RemoveFavorite(quoteid, userId);
}
}
}

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using Entity;
using Shared;
using Dto2Entities;
namespace ServicesApi
{
public class ImageService : IImagesService<ImageDTO>
{
private IImagesService<Images> imageService;
public ImageService(IImagesService<Images> image)
{
imageService = image;
}
public async Task AddImage(ImageDTO image)
{
await imageService.AddImage(image.ToEntity());
}
public async Task<PaginationResult<ImageDTO>> GetAllImage()
{
var images = imageService.GetAllImage().Result.items;
return new PaginationResult<ImageDTO>(images.Count(), 0, 10, images.ToDto());
}
public async Task<ImageDTO> GetImageById(int id)
{
return imageService.GetImageById(id).Result.ToDto();
}
public async Task<int> GetLastImageId()
{
return await imageService.GetLastImageId();
}
public async Task<PaginationResult<ImageDTO>> GetSomeImage(int index, int pageSize)
{
var images = imageService.GetSomeImage(index,pageSize).Result.items;
return new PaginationResult<ImageDTO>(images.Count(), 0, 10, images.ToDto());
}
public async Task RemoveImage(int id)
{
await imageService.RemoveImage(id);
}
public async Task UpdateImage(int id, ImageDTO image)
{
await imageService.UpdateImage(id, image.ToEntity());
}
}
}

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using Entity;
using Shared;
using Dto2Entities;
using static System.Net.Mime.MediaTypeNames;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace ServicesApi
{
public class QuestionService : IQuestionService<QuestionDTO>
{
private IQuestionService<Question> questionService;
public QuestionService(IQuestionService<Question> question)
{
questionService = question;
}
public async Task AddQuestion(QuestionDTO question)
{
await questionService.AddQuestion(question.ToEntity());
}
public async Task<int> CountQuestions()
{
return await questionService.CountQuestions();
}
public async Task<PaginationResult<QuestionDTO>> GetAllQuestion()
{
var questions = questionService.GetAllQuestion().Result.items;
return new PaginationResult<QuestionDTO>(questions.Count(), 0, 10, questions.ToDto());
}
public async Task<PaginationResult<QuestionDTO>> GetInvalidQuestion(int index, int pageSize)
{
var questions = questionService.GetInvalidQuestion(index,pageSize).Result.items;
return new PaginationResult<QuestionDTO>(questions.Count(), 0, 10, questions.ToDto());
}
public async Task<QuestionDTO> GetQuestionById(int id)
{
return questionService.GetQuestionById(id).Result.ToDto();
}
public async Task<QuestionDTO> GetRandomQuestion()
{
return questionService.GetRandomQuestion().Result.ToDto();
}
public async Task<QuestionDTO> GetRandomQuestionQuoteToCharacter()
{
return questionService.GetRandomQuestionQuoteToCharacter().Result.ToDto();
}
public async Task<QuestionDTO> GetRandomQuestionQuoteToSource()
{
return questionService.GetRandomQuestionQuoteToSource().Result.ToDto();
}
public async Task<PaginationResult<QuestionDTO>> GetSomeQuestion(int index, int pageSize)
{
var questions = questionService.GetSomeQuestion(index, pageSize).Result.items;
return new PaginationResult<QuestionDTO>(questions.Count(), 0, 10, questions.ToDto());
}
public async Task RemoveQuestion(int id)
{
await questionService.RemoveQuestion(id);
}
public async Task UpdateQuestion(int id, QuestionDTO question)
{
await questionService.UpdateQuestion(id, question.ToEntity());
}
public async Task ValidateQuestion(int id, bool isvalid)
{
await questionService.ValidateQuestion(id, isvalid);
}
}
}

@ -6,6 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contextlib\Contextlib.csproj" />
<ProjectReference Include="..\Dto2Entities\Dto2Entities.csproj" />

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using Entity;
using Shared;
using Dto2Entities;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace ServicesApi
{
public class SourceService : ISourceService<SourceDTO>
{
private ISourceService<Source> srcService;
public SourceService(ISourceService<Source> src)
{
srcService = src;
}
public async Task AddSource(SourceDTO source)
{
await srcService.AddSource(source.ToEntity());
}
public async Task<PaginationResult<SourceDTO>> GetAll()
{
var sources = srcService.GetAll().Result.items;
return new PaginationResult<SourceDTO>(sources.Count(), 0, 10, sources.ToDto());
}
public async Task<int> GetLastSourceId()
{
return await srcService.GetLastSourceId();
}
public async Task<SourceDTO> GetSourceByDate(string date)
{
return srcService.GetSourceByDate(date).Result.ToDto();
}
public async Task<SourceDTO> GetSourceById(int id)
{
return srcService.GetSourceById(id).Result.ToDto();
}
public async Task<SourceDTO> GetSourceByTitle(string title)
{
return srcService.GetSourceByTitle(title).Result.ToDto();
}
public async Task<SourceDTO> GetSourceByType(string type)
{
return srcService.GetSourceByType(type).Result.ToDto();
}
public async Task RemoveSource(int id)
{
await srcService.RemoveSource(id);
}
public async Task UpdateSource(int id, SourceDTO source)
{
await srcService.UpdateSource(id, source.ToEntity());
}
}
}

@ -30,7 +30,7 @@ namespace Shared
// Adds a new commenT.
// 'comment' is the comment object that will be added.
Task AddComment(TComment commentary);
Task AddComment(TComment commentary, int idQuote);
// Updates an existing comment identified by 'id'.
// 'id' is the unique identifier of the comment, and 'comment' contains the updated comment data.

@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -6,6 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />

@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -48,7 +48,7 @@ namespace WfApi.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateCommentary([FromBody] CommentaryDTO newCommentary)
public async Task<IActionResult> CreateCommentary([FromBody] CommentaryDTO newCommentary, int idQuote)
{
try
{
@ -57,14 +57,14 @@ namespace WfApi.Controllers
return BadRequest(new { message = "Comment data is required." });
}
var existingPlayer = _commentary.GetCommentaryById(newCommentary.Id).Result;
if (existingPlayer != null)
var existingCommentary = _commentary.GetCommentaryById(newCommentary.Id).Result;
if (existingCommentary != null)
{
return Conflict(new { message = "A comment with this ID already exists." });
}
_commentary.AddComment(newCommentary);
await _commentary.AddComment(newCommentary, idQuote);
return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary);
}
catch (Exception)

@ -5,11 +5,17 @@ using Contextlib;
using Entity;
using StubbedContextLib;
using ServicesApi;
var builder = WebApplication.CreateBuilder(args);
//API
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IUserService<UserDTO>, UserService>();
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<IQuestionService<QuestionDTO>, QuestionService>();
//EF
@ -18,8 +24,11 @@ builder.Services.AddScoped<WTFContext, StubWTFContext>();
builder.Services.AddScoped<IUserService<Users>, DbUsersManager>();
builder.Services.AddScoped<IQuoteService<Quote>, DbQuoteManager>();
//builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>();
builder.Services.AddScoped<ICommentaryService<Commentary>, DbCommentaryManager>();
builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>();
builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>();
builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>();
//...
// Add services to the container.

@ -11,6 +11,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="NSwag.AspNetCore" Version="14.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />

@ -11,6 +11,10 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.72" />

Loading…
Cancel
Save