using System; using System.Collections.Generic; using System.Linq; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using DTO; using Dto2Entities; using Entity; using Shared; namespace ServicesApi { public class QuoteService : IQuoteService { private IQuoteService quoteService; public QuoteService(IQuoteService quote) { quoteService = quote; } public async Task AddQuote(QuoteDTO quote) { return (await quoteService.AddQuote(quote.ToEntity())).ToDto(); } public async Task> GetAllQuote() { 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) { var quotes = quoteService.GetAllQuoteLang(index, pageSize,lang).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task GetDailyQuote(DateOnly date, int lang) { return quoteService.GetDailyQuote(date, lang).Result.ToDto(); } public async Task> GetFavorites(int index, int pageSize, int UserId) { 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) { 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) { var quotes = quoteService.GetInvalidQuote(index, pageSize).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task GetLastQuoteId() { return await quoteService.GetLastQuoteId(); } public async Task GetQuoteById(int id) { var quote= quoteService.GetQuoteById(id).Result; if (quote != null) return quote.ToDto(); else return null; } public async Task> GetSomeQuote(int index, int pageSize) { 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) { 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) { var quotes = quoteService.GetValidQuote(index, pageSize).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task RemoveQuote(int quoteId) { await quoteService.RemoveQuote(quoteId); } public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) { var quotes = quoteService.SearchByCharacter(character, index, pageSize, lang).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> SearchByContent(string content, int index, int pageSize, int lang) { var quotes = quoteService.SearchByContent(content, index, pageSize, lang).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> SearchBySource(string source, int index, int pageSize, int lang) { var quotes = quoteService.SearchBySource(source, index, pageSize, lang).Result.items; return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task UpdateQuote(int quoteId, QuoteDTO quote) { await quoteService.UpdateQuote(quoteId, quote.ToEntity()); } public async Task ValidateQuote(int quoteId, bool isValidate) { await quoteService.ValidateQuote(quoteId, isValidate); } } }