Fix all comments were returned instead of post-specific comments
This commit is contained in:
@@ -179,7 +179,7 @@ public class PostController(
|
||||
if (post == null) return NotFound();
|
||||
|
||||
var fileRecord = await fileService.GetFileById(fileId);
|
||||
if (fileRecord == null) return NotFound();
|
||||
if (fileRecord == null || post.File.Id != fileRecord.Id) return NotFound();
|
||||
|
||||
// If not the resource owner
|
||||
var userId = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
@@ -264,7 +264,7 @@ public class PostController(
|
||||
if (post == null) return NotFound();
|
||||
|
||||
var fileRecord = await fileService.GetFileById(fileId);
|
||||
if (fileRecord == null) return NotFound();
|
||||
if (fileRecord == null || post.File.Id != fileRecord.Id) return NotFound();
|
||||
|
||||
// Ensure the file has been successfully uploaded and finalized
|
||||
if (string.IsNullOrEmpty(fileRecord.FilePath) || fileRecord.FinishedDate == null)
|
||||
@@ -466,7 +466,7 @@ public class PostController(
|
||||
if (entry == null) return NotFound();
|
||||
|
||||
var comment = await commentService.GetById(commentId);
|
||||
if (comment == null) return NotFound();
|
||||
if (comment == null || entry.Id != comment.OriginalPost.Id) return NotFound();
|
||||
|
||||
return Ok(CommentDto.FromComment(comment));
|
||||
}
|
||||
@@ -491,7 +491,7 @@ public class PostController(
|
||||
var post = await postService.GetById(postId);
|
||||
if (post == null) return NotFound();
|
||||
|
||||
var list = await commentService.GetAll(pageNumber);
|
||||
var list = await commentService.GetAll(postId, pageNumber);
|
||||
var newItems = list.Items.Select(CommentDto.FromComment).ToList();
|
||||
return Ok(new PagedList<CommentDto>(newItems, list.CurrentPage, list.PageSize, list.TotalCount));
|
||||
}
|
||||
@@ -519,7 +519,7 @@ public class PostController(
|
||||
if (post == null) return NotFound();
|
||||
|
||||
var comment = await commentService.GetById(commentId);
|
||||
if (comment == null) return NotFound();
|
||||
if (comment == null || post.Id != comment.OriginalPost.Id) return NotFound();
|
||||
|
||||
var userId = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
var isAdmin = HttpContext.User.IsInRole(UserRoles.Admin);
|
||||
@@ -556,8 +556,8 @@ public class PostController(
|
||||
if (post == null) return NotFound();
|
||||
|
||||
var comment = await commentService.GetById(commentId);
|
||||
if (comment == null) return NotFound();
|
||||
|
||||
if (comment == null || post.Id != comment.OriginalPost.Id) return NotFound();
|
||||
|
||||
var userId = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
var isAdmin = HttpContext.User.IsInRole(UserRoles.Admin);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user