diff --git a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj
index 9a4ee54..73a6de7 100644
--- a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj
+++ b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj
@@ -8,6 +8,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs
index f39e4df..78f7ae4 100644
--- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs
+++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs
@@ -27,13 +27,30 @@ namespace Contextlib
/// The comment to add.
/// A task representing the asynchronous operation.
/// Thrown when the comment is null.
- 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();
}
diff --git a/WF_EF_Api/DTO/DTO.csproj b/WF_EF_Api/DTO/DTO.csproj
index bb23fb7..99264a0 100644
--- a/WF_EF_Api/DTO/DTO.csproj
+++ b/WF_EF_Api/DTO/DTO.csproj
@@ -6,4 +6,11 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj
index beed701..7455396 100644
--- a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj
+++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj
@@ -6,6 +6,13 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/Entity/Entity.csproj b/WF_EF_Api/Entity/Entity.csproj
index bb23fb7..99264a0 100644
--- a/WF_EF_Api/Entity/Entity.csproj
+++ b/WF_EF_Api/Entity/Entity.csproj
@@ -6,4 +6,11 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/ServicesApi/CharacterService.cs b/WF_EF_Api/ServicesApi/CharacterService.cs
new file mode 100644
index 0000000..399586a
--- /dev/null
+++ b/WF_EF_Api/ServicesApi/CharacterService.cs
@@ -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
+ {
+ private ICharacterService characterService;
+
+ public CharacterService(ICharacterService character)
+ {
+ characterService = character;
+ }
+
+
+ public async Task AddCharacter(CharacterDTO character)
+ {
+ await characterService.AddCharacter(character.ToEntity());
+ }
+
+ public async Task> GetAll()
+ {
+ var characters = characterService.GetAll().Result.items;
+ return new PaginationResult(characters.Count(), 0, 10, characters.ToDto());
+ }
+
+ public async Task GetCharById(int id)
+ {
+ return characterService.GetCharById(id).Result.ToDto();
+ }
+
+ public async Task GetCharByName(string name)
+ {
+ return characterService.GetCharByName(name).Result.ToDto();
+ }
+
+ public async Task 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());
+ }
+ }
+}
diff --git a/WF_EF_Api/ServicesApi/CommentaryService.cs b/WF_EF_Api/ServicesApi/CommentaryService.cs
index 211f6a4..e151c03 100644
--- a/WF_EF_Api/ServicesApi/CommentaryService.cs
+++ b/WF_EF_Api/ServicesApi/CommentaryService.cs
@@ -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)
diff --git a/WF_EF_Api/ServicesApi/FavoriteService.cs b/WF_EF_Api/ServicesApi/FavoriteService.cs
new file mode 100644
index 0000000..d3b3802
--- /dev/null
+++ b/WF_EF_Api/ServicesApi/FavoriteService.cs
@@ -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);
+ }
+ }
+}
diff --git a/WF_EF_Api/ServicesApi/ImageService.cs b/WF_EF_Api/ServicesApi/ImageService.cs
new file mode 100644
index 0000000..caefb31
--- /dev/null
+++ b/WF_EF_Api/ServicesApi/ImageService.cs
@@ -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
+ {
+ private IImagesService imageService;
+
+ public ImageService(IImagesService image)
+ {
+ imageService = image;
+ }
+
+ public async Task AddImage(ImageDTO image)
+ {
+ await imageService.AddImage(image.ToEntity());
+ }
+
+ public async Task> GetAllImage()
+ {
+ var images = imageService.GetAllImage().Result.items;
+ return new PaginationResult(images.Count(), 0, 10, images.ToDto());
+ }
+
+ public async Task GetImageById(int id)
+ {
+ return imageService.GetImageById(id).Result.ToDto();
+ }
+
+ public async Task GetLastImageId()
+ {
+ return await imageService.GetLastImageId();
+ }
+
+ public async Task> GetSomeImage(int index, int pageSize)
+ {
+ var images = imageService.GetSomeImage(index,pageSize).Result.items;
+ return new PaginationResult(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());
+ }
+ }
+}
diff --git a/WF_EF_Api/ServicesApi/QuestionService.cs b/WF_EF_Api/ServicesApi/QuestionService.cs
new file mode 100644
index 0000000..4d71308
--- /dev/null
+++ b/WF_EF_Api/ServicesApi/QuestionService.cs
@@ -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
+ {
+ private IQuestionService questionService;
+
+ public QuestionService(IQuestionService question)
+ {
+ questionService = question;
+ }
+
+
+
+ public async Task AddQuestion(QuestionDTO question)
+ {
+ await questionService.AddQuestion(question.ToEntity());
+ }
+
+ public async Task CountQuestions()
+ {
+ return await questionService.CountQuestions();
+ }
+
+ public async Task> GetAllQuestion()
+ {
+ var questions = questionService.GetAllQuestion().Result.items;
+ return new PaginationResult(questions.Count(), 0, 10, questions.ToDto());
+ }
+
+ public async Task> GetInvalidQuestion(int index, int pageSize)
+ {
+ var questions = questionService.GetInvalidQuestion(index,pageSize).Result.items;
+ return new PaginationResult(questions.Count(), 0, 10, questions.ToDto());
+ }
+
+ public async Task GetQuestionById(int id)
+ {
+ return questionService.GetQuestionById(id).Result.ToDto();
+ }
+
+ public async Task GetRandomQuestion()
+ {
+ return questionService.GetRandomQuestion().Result.ToDto();
+ }
+
+ public async Task GetRandomQuestionQuoteToCharacter()
+ {
+ return questionService.GetRandomQuestionQuoteToCharacter().Result.ToDto();
+ }
+
+ public async Task GetRandomQuestionQuoteToSource()
+ {
+ return questionService.GetRandomQuestionQuoteToSource().Result.ToDto();
+ }
+
+ public async Task> GetSomeQuestion(int index, int pageSize)
+ {
+ var questions = questionService.GetSomeQuestion(index, pageSize).Result.items;
+ return new PaginationResult(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);
+ }
+ }
+}
diff --git a/WF_EF_Api/ServicesApi/ServicesApi.csproj b/WF_EF_Api/ServicesApi/ServicesApi.csproj
index 89650c8..074190e 100644
--- a/WF_EF_Api/ServicesApi/ServicesApi.csproj
+++ b/WF_EF_Api/ServicesApi/ServicesApi.csproj
@@ -6,6 +6,13 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/ServicesApi/SourceService.cs b/WF_EF_Api/ServicesApi/SourceService.cs
new file mode 100644
index 0000000..f767fdc
--- /dev/null
+++ b/WF_EF_Api/ServicesApi/SourceService.cs
@@ -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
+ {
+ private ISourceService srcService;
+
+ public SourceService(ISourceService src)
+ {
+ srcService = src;
+ }
+ public async Task AddSource(SourceDTO source)
+ {
+ await srcService.AddSource(source.ToEntity());
+ }
+
+ public async Task> GetAll()
+ {
+ var sources = srcService.GetAll().Result.items;
+ return new PaginationResult(sources.Count(), 0, 10, sources.ToDto());
+ }
+
+ public async Task GetLastSourceId()
+ {
+ return await srcService.GetLastSourceId();
+ }
+
+ public async Task GetSourceByDate(string date)
+ {
+ return srcService.GetSourceByDate(date).Result.ToDto();
+ }
+
+ public async Task GetSourceById(int id)
+ {
+ return srcService.GetSourceById(id).Result.ToDto();
+ }
+
+ public async Task GetSourceByTitle(string title)
+ {
+ return srcService.GetSourceByTitle(title).Result.ToDto();
+ }
+
+ public async Task 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());
+ }
+ }
+}
diff --git a/WF_EF_Api/Shared/IComentaryService.cs b/WF_EF_Api/Shared/IComentaryService.cs
index b546360..3808b6d 100644
--- a/WF_EF_Api/Shared/IComentaryService.cs
+++ b/WF_EF_Api/Shared/IComentaryService.cs
@@ -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.
diff --git a/WF_EF_Api/Shared/Shared.csproj b/WF_EF_Api/Shared/Shared.csproj
index bb23fb7..99264a0 100644
--- a/WF_EF_Api/Shared/Shared.csproj
+++ b/WF_EF_Api/Shared/Shared.csproj
@@ -6,4 +6,11 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/StubApi/StubApi.csproj b/WF_EF_Api/StubApi/StubApi.csproj
index de86de5..2df8a10 100644
--- a/WF_EF_Api/StubApi/StubApi.csproj
+++ b/WF_EF_Api/StubApi/StubApi.csproj
@@ -6,6 +6,13 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj
index bb23fb7..99264a0 100644
--- a/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj
+++ b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj
@@ -6,4 +6,11 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs
index 737acea..29b579b 100644
--- a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs
+++ b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs
@@ -48,7 +48,7 @@ namespace WfApi.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
- public async Task CreateCommentary([FromBody] CommentaryDTO newCommentary)
+ public async Task 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)
diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs
index 184781b..04a65b8 100644
--- a/WF_EF_Api/WfApi/Program.cs
+++ b/WF_EF_Api/WfApi/Program.cs
@@ -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, UserService>();
builder.Services.AddScoped, QuoteService>();
builder.Services.AddScoped, CommentaryService>();
+builder.Services.AddScoped, CharacterService>();
+builder.Services.AddScoped, ImageService>();
+builder.Services.AddScoped, SourceService>();
+builder.Services.AddScoped, QuestionService>();
//EF
@@ -17,8 +23,11 @@ builder.Services.AddScoped();
builder.Services.AddScoped, DbUsersManager>();
builder.Services.AddScoped, DbQuoteManager>();
-//builder.Services.AddScoped, DbCharacterManager>();
builder.Services.AddScoped, DbCommentaryManager>();
+builder.Services.AddScoped, DbCharacterManager>();
+builder.Services.AddScoped, DbImagesManager>();
+builder.Services.AddScoped, SourceService>();
+builder.Services.AddScoped, QuestionService>();
//...
// Add services to the container.
diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj
index 0416a92..638d2f5 100644
--- a/WF_EF_Api/WfApi/WfApi.csproj
+++ b/WF_EF_Api/WfApi/WfApi.csproj
@@ -11,6 +11,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/WF_EF_Api/XUnitTest/XUnitTest.csproj b/WF_EF_Api/XUnitTest/XUnitTest.csproj
index 312f514..0578038 100644
--- a/WF_EF_Api/XUnitTest/XUnitTest.csproj
+++ b/WF_EF_Api/XUnitTest/XUnitTest.csproj
@@ -11,6 +11,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+