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 CommentaryService : ICommentaryService { private ICommentaryService commentaryService; public CommentaryService(ICommentaryService commentary) { commentaryService = commentary; } public async Task AddComment(CommentaryDTO commentary, int idQuote) { await commentaryService.AddComment(commentary.ToEntity(), idQuote); } public async Task DeleteCommentaryForQuote(int quoteId) { await commentaryService.DeleteCommentaryForQuote(quoteId); } public async Task DeleteCommentaryForUser(int userId) { await commentaryService.DeleteCommentaryForUser(userId); } public async Task> GetAllCommentary() { var commentaries = commentaryService.GetAllCommentary().Result.items; return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); } public async Task GetCommentaryById(int id) { try { return (await commentaryService.GetCommentaryById(id)).ToDto(); } catch(KeyNotFoundException) { throw new KeyNotFoundException($"No comments found with the given ID: {id}."); } } public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize) { var commentaries = commentaryService.GetCommentaryByQuote(quoteId,index,pageSize).Result.items; return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); } public async Task> GetCommentaryByUser(int userId, int index, int pageSize) { var commentaries = commentaryService.GetCommentaryByUser(userId, index,pageSize).Result.items; return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); } public async Task LastCommentaryId() { return await commentaryService.LastCommentaryId(); } public async Task RemoveCommentary(int id) { await commentaryService.RemoveCommentary(id); } public async Task UpdateCommentary(int id, CommentaryDTO commentary) { await commentaryService.UpdateCommentary(id,commentary.ToEntity()); } } }