Skip to content

Commit d41f1c3

Browse files
committed
Return parentId in comment output. Return value from delete operation, for event use.
1 parent 1ee0886 commit d41f1c3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/main/kotlin/no/nav/klage/document/api/CommentsController.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ class CommentsController(
141141
@PathVariable("documentId") documentId: UUID,
142142
@PathVariable("commentId") commentId: UUID,
143143
@RequestBody deleteCommentInput: DeleteCommentInput
144-
) {
144+
): CommentView {
145145
log("deleteCommentWithPossibleThread called with id $documentId and commentId $commentId")
146-
commentService.deleteComment(commentId = commentId, loggedInIdent = getIdent()!!, behandlingTildeltIdent = deleteCommentInput.behandlingTildeltIdent)
146+
return mapCommentToView(commentService.deleteComment(commentId = commentId, loggedInIdent = getIdent()!!, behandlingTildeltIdent = deleteCommentInput.behandlingTildeltIdent))
147147
}
148148

149149
private fun mapCommentToView(comment: Comment): CommentView =
@@ -156,7 +156,8 @@ class CommentsController(
156156
),
157157
comments = comment.comments.map { mapCommentToView(it) },
158158
created = comment.created,
159-
modified = comment.modified
159+
modified = comment.modified,
160+
parentId = comment.parentCommentId,
160161
)
161162

162163
private fun log(message: String) {

src/main/kotlin/no/nav/klage/document/api/views/CommentView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ data class CommentView(
99
val author: Author,
1010
val comments: List<CommentView> = emptyList(),
1111
val created: LocalDateTime,
12-
val modified: LocalDateTime
12+
val modified: LocalDateTime,
13+
val parentId: UUID?,
1314
) {
1415
data class Author(
1516
val name: String,

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,26 @@ class CommentService(private val commentRepository: CommentRepository) {
6969
commentId: UUID,
7070
loggedInIdent: String,
7171
behandlingTildeltIdent: String?
72-
) {
72+
): Comment {
7373
val loggedInIsDocumentOwner = loggedInIdent == behandlingTildeltIdent
7474
val comment = commentRepository.getReferenceById(commentId)
7575
if (!loggedInIsDocumentOwner && comment.authorIdent != loggedInIdent) {
7676
throw MissingAccessException("Not allowed to delete others comment when not document owner")
7777
}
78+
79+
val commentCopy = Comment(
80+
id = commentId,
81+
parentCommentId = comment.parentCommentId,
82+
documentId = comment.documentId,
83+
text = "",
84+
authorName = comment.authorName,
85+
authorIdent = comment.authorIdent,
86+
comments = comment.comments,
87+
created = comment.created,
88+
modified = LocalDateTime.now(),
89+
)
7890
commentRepository.delete(comment)
91+
92+
return commentCopy
7993
}
8094
}

0 commit comments

Comments
 (0)