You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.8 KiB
83 lines
2.8 KiB
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<CommentaryDTO>
|
|
{
|
|
private ICommentaryService<Commentary> commentaryService;
|
|
|
|
public CommentaryService(ICommentaryService<Commentary> 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<PaginationResult<CommentaryDTO>> GetAllCommentary()
|
|
{
|
|
var commentaries = commentaryService.GetAllCommentary().Result.items;
|
|
return new PaginationResult<CommentaryDTO>(commentaries.Count(), 0, 10, commentaries.ToDto());
|
|
}
|
|
|
|
public async Task<CommentaryDTO> 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<PaginationResult<CommentaryDTO>> GetCommentaryByQuote(int quoteId, int index, int pageSize)
|
|
{
|
|
var commentaries = commentaryService.GetCommentaryByQuote(quoteId,index,pageSize).Result.items;
|
|
return new PaginationResult<CommentaryDTO>(commentaries.Count(), 0, 10, commentaries.ToDto());
|
|
}
|
|
|
|
public async Task<PaginationResult<CommentaryDTO>> GetCommentaryByUser(int userId, int index, int pageSize)
|
|
{
|
|
var commentaries = commentaryService.GetCommentaryByUser(userId, index,pageSize).Result.items;
|
|
return new PaginationResult<CommentaryDTO>(commentaries.Count(), 0, 10, commentaries.ToDto());
|
|
}
|
|
|
|
public async Task<int> 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());
|
|
}
|
|
}
|
|
}
|