Skip to content

Commit 4874988

Browse files
committed
Get in order
1 parent 0835232 commit 4874988

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/main/kotlin/no/nav/klage/document/domain/Comment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Comment(
2626
@JoinColumn(name = "parent_comment_id", referencedColumnName = "id")
2727
@Fetch(FetchMode.SELECT)
2828
@BatchSize(size = 100)
29+
@OrderBy("created asc")
2930
val comments: MutableSet<Comment> = mutableSetOf(),
3031
@Column(name = "created")
3132
val created: LocalDateTime,

src/main/kotlin/no/nav/klage/document/repositories/CommentRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ interface CommentRepository : JpaRepository<Comment, UUID> {
99
/**
1010
* Only find parent comments
1111
*/
12-
fun findByDocumentIdAndParentCommentIdIsNull(documentId: UUID): List<Comment>
12+
fun findByDocumentIdAndParentCommentIdIsNullOrderByCreatedAsc(documentId: UUID): List<Comment>
1313

1414
}

src/main/kotlin/no/nav/klage/document/service/CommentService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CommentService(private val commentRepository: CommentRepository) {
4747
}
4848

4949
fun getComments(documentId: UUID): List<Comment> {
50-
return commentRepository.findByDocumentIdAndParentCommentIdIsNull(documentId)
50+
return commentRepository.findByDocumentIdAndParentCommentIdIsNullOrderByCreatedAsc(documentId)
5151
}
5252

5353
fun getComment(commentId: UUID): Comment {

src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,34 @@ class RepositoryTest {
6565
val comment2 = Comment(
6666
documentId = document.id,
6767
parentCommentId = comment1.id,
68-
text = "my sub comment 2",
68+
text = "my sub comment 1",
6969
authorName = "Kajsa Anka",
7070
authorIdent = "Z654321",
7171
created = now.plusDays(2),
7272
modified = now.plusDays(2)
7373
)
7474

75+
val comment3 = Comment(
76+
documentId = document.id,
77+
parentCommentId = comment1.id,
78+
text = "my sub comment 2",
79+
authorName = "Kajsa Anka",
80+
authorIdent = "Z654321",
81+
created = now.plusDays(3),
82+
modified = now.plusDays(3)
83+
)
84+
7585
commentRepository.save(comment1)
7686
commentRepository.save(comment2)
87+
commentRepository.save(comment3)
7788

7889
testEntityManager.flush()
7990
testEntityManager.clear()
8091

81-
val comments = commentRepository.findByDocumentIdAndParentCommentIdIsNull(document.id)
92+
val comments = commentRepository.findByDocumentIdAndParentCommentIdIsNullOrderByCreatedAsc(document.id)
8293

83-
assertThat(comments.first().comments).hasSize(1)
94+
assertThat(comments.first().comments).hasSize(2)
95+
assertThat(comments.first().comments.first()).isEqualTo(comment2)
8496
}
8597

8698
}

0 commit comments

Comments
 (0)