From 4b1edf0e1697f01f1aa3726c1802e4c4178f6029 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Mon, 31 Mar 2025 16:18:43 +0200 Subject: [PATCH] Service des citations --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 126 +++++++++++++++++++++++++ WF_EF_Api/Contextlib/DbUsersManager.cs | 2 + WF_EF_Api/ServicesApi/QuoteService.cs | 18 ++-- WF_EF_Api/WfApi/Program.cs | 8 +- 4 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbQuoteManager.cs diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs new file mode 100644 index 0000000..a5fc2d1 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Shared; + +namespace Contextlib +{ + public class DbQuoteManager : IQuoteService + { + private WTFContext _context; + private GenericRepository _repo; + + public DbQuoteManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(_context); + } + + + + + + public async Task AddQuote(Quote quote) + { + if (quote == null) + { + throw new ArgumentNullException(nameof(quote), "quote cannot be null."); + } + _repo.Insert(quote); + await _context.SaveChangesAsync(); + } + + public async Task> GetAllQuote() + { + List quotes = _repo.GetItems(0, _repo.Count(), [nameof(Quote.Id)]).ToList(); + return new PaginationResult(quotes.Count, 0, quotes.Count, quotes); + } + + public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task GetDailyQuote(DateOnly date, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetFavorites(int index, int pageSize, int UserId) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task GetLastQuoteId() + { + throw new NotImplementedException(); + } + + public async Task GetQuoteById(int id) + { + throw new NotImplementedException(); + } + + public async Task> GetSomeQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task> GetSuggestions(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetValidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + + + + + public async Task RemoveQuote(int quoteId) + { + throw new NotImplementedException(); + } + + public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchByContent(string content, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchBySource(string source, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task UpdateQuote(int quoteId, Quote quote) + { + throw new NotImplementedException(); + } + + public async Task ValidateQuote(int quoteId, bool isValidate) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs index e4d2940..6389403 100644 --- a/WF_EF_Api/Contextlib/DbUsersManager.cs +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -19,6 +19,8 @@ namespace Contextlib _repo = new GenericRepository(_context); } + + public async Task AddUser(Users user) { if (user == null) { diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs index eee85b7..2a76c86 100644 --- a/WF_EF_Api/ServicesApi/QuoteService.cs +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -26,7 +26,8 @@ namespace ServicesApi public async Task> GetAllQuote() { - throw new NotImplementedException(); + var quotes = quoteService.GetAllQuote().Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetAllQuoteLang(int index, int pageSize, int lang) @@ -41,17 +42,20 @@ namespace ServicesApi public async Task> GetFavorites(int index, int pageSize, int UserId) { - throw new NotImplementedException(); + var quotes = quoteService.GetFavorites(index, pageSize, UserId).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetInvalidQuote(int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.GetInvalidQuote(index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetInvalidQuote(int index, int pageSize) { - throw new NotImplementedException(); + var quotes = quoteService.GetInvalidQuote(index, pageSize).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task GetLastQuoteId() @@ -66,12 +70,14 @@ namespace ServicesApi public async Task> GetSomeQuote(int index, int pageSize) { - throw new NotImplementedException(); + var quotes = quoteService.GetSomeQuote(index, pageSize).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetSuggestions(int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.GetSuggestions(index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetValidQuote(int index, int pageSize) diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 01c0c1e..54d221a 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -8,15 +8,15 @@ using ServicesApi; var builder = WebApplication.CreateBuilder(args); //API builder.Services.AddScoped, UserService>(); -builder.Services.AddScoped, QuoteServiceStub>(); // Retirer "Stub" +builder.Services.AddScoped, QuoteService>(); //EF builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); -// builder.Services.AddScoped, DbQuoteManager>(); Quand DbQuoteManager sera présent -//builder.Services.AddScoped, DbCharacterManager>(); -//builder.Services.AddScoped, DbCommentaryManager>(); +builder.Services.AddScoped, DbQuoteManager>(); +//builder.Services.AddScoped, DbCharacterManager>(); +//builder.Services.AddScoped, DbCommentaryManager>(); //... // Add services to the container.