Fix all comments were returned instead of post-specific comments
This commit is contained in:
@@ -9,7 +9,7 @@ public interface ICommentService
|
||||
{
|
||||
Task<Comment> Create(string text, User author, Post post);
|
||||
Task<Comment?> GetById(int commentId);
|
||||
Task<PagedList<Comment>> GetAll(int pageNumber = 1);
|
||||
Task<PagedList<Comment>> GetAll(int postId, int pageNumber = 1);
|
||||
Task<bool> Delete(Comment comment);
|
||||
Task<Comment> Update(Comment comment);
|
||||
}
|
||||
@@ -40,10 +40,11 @@ public class CommentService(ImgBoardContext context): ICommentService
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<PagedList<Comment>> GetAll(int pageNumber = 1)
|
||||
public async Task<PagedList<Comment>> GetAll(int postId, int pageNumber = 1)
|
||||
{
|
||||
var totalCount = await context.Comments.CountAsync();
|
||||
var totalCount = await context.Comments.Where(c => c.OriginalPost.Id == postId).CountAsync();
|
||||
var items = await context.Comments
|
||||
.Where(c => c.OriginalPost.Id == postId)
|
||||
.Skip((pageNumber - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.Include(b => b.Author)
|
||||
|
||||
Reference in New Issue
Block a user