diff --git a/src/main/kotlin/no/nav/klage/document/api/CommentsController.kt b/src/main/kotlin/no/nav/klage/document/api/CommentsController.kt index eb36285..ff082ab 100644 --- a/src/main/kotlin/no/nav/klage/document/api/CommentsController.kt +++ b/src/main/kotlin/no/nav/klage/document/api/CommentsController.kt @@ -141,9 +141,9 @@ class CommentsController( @PathVariable("documentId") documentId: UUID, @PathVariable("commentId") commentId: UUID, @RequestBody deleteCommentInput: DeleteCommentInput - ) { + ): CommentView { log("deleteCommentWithPossibleThread called with id $documentId and commentId $commentId") - commentService.deleteComment(commentId = commentId, loggedInIdent = getIdent()!!, behandlingTildeltIdent = deleteCommentInput.behandlingTildeltIdent) + return mapCommentToView(commentService.deleteComment(commentId = commentId, loggedInIdent = getIdent()!!, behandlingTildeltIdent = deleteCommentInput.behandlingTildeltIdent)) } private fun mapCommentToView(comment: Comment): CommentView = @@ -156,7 +156,8 @@ class CommentsController( ), comments = comment.comments.map { mapCommentToView(it) }, created = comment.created, - modified = comment.modified + modified = comment.modified, + parentId = comment.parentCommentId, ) private fun log(message: String) { diff --git a/src/main/kotlin/no/nav/klage/document/api/views/CommentView.kt b/src/main/kotlin/no/nav/klage/document/api/views/CommentView.kt index 1efde4c..ed4baf8 100644 --- a/src/main/kotlin/no/nav/klage/document/api/views/CommentView.kt +++ b/src/main/kotlin/no/nav/klage/document/api/views/CommentView.kt @@ -9,7 +9,8 @@ data class CommentView( val author: Author, val comments: List = emptyList(), val created: LocalDateTime, - val modified: LocalDateTime + val modified: LocalDateTime, + val parentId: UUID?, ) { data class Author( val name: String, diff --git a/src/main/kotlin/no/nav/klage/document/service/CommentService.kt b/src/main/kotlin/no/nav/klage/document/service/CommentService.kt index 3f0f5f3..8ea8b49 100644 --- a/src/main/kotlin/no/nav/klage/document/service/CommentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/CommentService.kt @@ -1,5 +1,6 @@ package no.nav.klage.document.service +import no.nav.klage.document.api.views.CommentView import no.nav.klage.document.domain.Comment import no.nav.klage.document.exceptions.MissingAccessException import no.nav.klage.document.repositories.CommentRepository @@ -69,12 +70,14 @@ class CommentService(private val commentRepository: CommentRepository) { commentId: UUID, loggedInIdent: String, behandlingTildeltIdent: String? - ) { + ): Comment { val loggedInIsDocumentOwner = loggedInIdent == behandlingTildeltIdent val comment = commentRepository.getReferenceById(commentId) if (!loggedInIsDocumentOwner && comment.authorIdent != loggedInIdent) { throw MissingAccessException("Not allowed to delete others comment when not document owner") } commentRepository.delete(comment) + + return comment } } \ No newline at end of file