Skip to content

Commit 1f9abf4

Browse files
authored
Merge pull request #195 from navikt/return_values
Return parentId in comment output. Return value from delete operation…
2 parents 1ee0886 + 29b1152 commit 1f9abf4

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.klage.document.service
22

3+
import no.nav.klage.document.api.views.CommentView
34
import no.nav.klage.document.domain.Comment
45
import no.nav.klage.document.exceptions.MissingAccessException
56
import no.nav.klage.document.repositories.CommentRepository
@@ -69,12 +70,14 @@ class CommentService(private val commentRepository: CommentRepository) {
6970
commentId: UUID,
7071
loggedInIdent: String,
7172
behandlingTildeltIdent: String?
72-
) {
73+
): Comment {
7374
val loggedInIsDocumentOwner = loggedInIdent == behandlingTildeltIdent
7475
val comment = commentRepository.getReferenceById(commentId)
7576
if (!loggedInIsDocumentOwner && comment.authorIdent != loggedInIdent) {
7677
throw MissingAccessException("Not allowed to delete others comment when not document owner")
7778
}
7879
commentRepository.delete(comment)
80+
81+
return comment
7982
}
8083
}

0 commit comments

Comments
 (0)