From d41f1c320ec3da2bc9a625be87d897ab0aa632a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20N=2E=20Wed=C3=B8e?= Date: Thu, 5 Sep 2024 11:02:22 +0200 Subject: [PATCH 1/2] Return parentId in comment output. Return value from delete operation, for event use. --- .../nav/klage/document/api/CommentsController.kt | 7 ++++--- .../nav/klage/document/api/views/CommentView.kt | 3 ++- .../nav/klage/document/service/CommentService.kt | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) 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..5f9ab29 100644 --- a/src/main/kotlin/no/nav/klage/document/service/CommentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/CommentService.kt @@ -69,12 +69,26 @@ 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") } + + val commentCopy = Comment( + id = commentId, + parentCommentId = comment.parentCommentId, + documentId = comment.documentId, + text = "", + authorName = comment.authorName, + authorIdent = comment.authorIdent, + comments = comment.comments, + created = comment.created, + modified = LocalDateTime.now(), + ) commentRepository.delete(comment) + + return commentCopy } } \ No newline at end of file From 29b1152f77da8b0c86e6dabf0037d4a1ea784ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20N=2E=20Wed=C3=B8e?= Date: Thu, 5 Sep 2024 14:26:30 +0200 Subject: [PATCH 2/2] Adjust return value from delete. --- .../nav/klage/document/service/CommentService.kt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) 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 5f9ab29..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 @@ -75,20 +76,8 @@ class CommentService(private val commentRepository: CommentRepository) { if (!loggedInIsDocumentOwner && comment.authorIdent != loggedInIdent) { throw MissingAccessException("Not allowed to delete others comment when not document owner") } - - val commentCopy = Comment( - id = commentId, - parentCommentId = comment.parentCommentId, - documentId = comment.documentId, - text = "", - authorName = comment.authorName, - authorIdent = comment.authorIdent, - comments = comment.comments, - created = comment.created, - modified = LocalDateTime.now(), - ) commentRepository.delete(comment) - return commentCopy + return comment } } \ No newline at end of file