Fix #3438: Getting Wrong postsCount for thread (#3446)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-03-15 18:14:59 -07:00 committed by GitHub
parent 0a80820742
commit 23e0aff20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -198,7 +198,11 @@ public class FeedRepository {
List<Post> posts = thread.getPosts();
// Remove the post to be deleted from the posts list
posts = posts.stream().filter(p -> !p.getId().equals(post.getId())).collect(Collectors.toList());
thread.withUpdatedAt(System.currentTimeMillis()).withUpdatedBy(userName).withPosts(posts);
thread
.withUpdatedAt(System.currentTimeMillis())
.withUpdatedBy(userName)
.withPosts(posts)
.withPostsCount(posts.size());
// update the json document
dao.feedDAO().update(thread.getId().toString(), JsonUtils.pojoToJson(thread));

View File

@ -483,6 +483,10 @@ public class FeedResourceTest extends CatalogApplicationTest {
// Check if get posts API returns the post
PostList postList = listPosts(thread.getId().toString(), AUTH_HEADERS);
assertTrue(postList.getData().isEmpty());
// validate posts count
Thread getThread = getThread(thread.getId(), AUTH_HEADERS);
assertEquals(0, getThread.getPostsCount());
}
@Test