Skip to content

Commit 39e8b30

Browse files
committed
Delete document
1 parent 4874988 commit 39e8b30

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DocumentController(
5252
@PathVariable("documentId") documentId: UUID,
5353
@RequestBody json: String
5454
): DocumentView {
55-
logger.debug("updateDocument: received json: {}", json)
55+
logger.debug("updateDocument with id {}: received json: {}", documentId, json)
5656
return mapToDocumentView(documentService.updateDocument(documentId, json))
5757
}
5858

@@ -62,10 +62,20 @@ class DocumentController(
6262
)
6363
@GetMapping("/{documentId}")
6464
fun getDocument(@PathVariable("documentId") documentId: UUID): DocumentView {
65-
logger.debug("getDocument")
65+
logger.debug("getDocument with id {}", documentId)
6666
return mapToDocumentView(documentService.getDocument(documentId))
6767
}
6868

69+
@ApiOperation(
70+
value = "Delete document",
71+
notes = "Delete document"
72+
)
73+
@DeleteMapping("/{documentId}")
74+
fun deleteDocument(@PathVariable("documentId") documentId: UUID) {
75+
logger.debug("deleteDocument with id {}", documentId)
76+
documentService.deleteDocument(documentId)
77+
}
78+
6979
@ApiOperation(
7080
value = "Create comment for a given document",
7181
notes = "Create comment for a given document"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ interface CommentRepository : JpaRepository<Comment, UUID> {
1111
*/
1212
fun findByDocumentIdAndParentCommentIdIsNullOrderByCreatedAsc(documentId: UUID): List<Comment>
1313

14+
fun deleteByDocumentId(documentId: UUID)
15+
1416
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package no.nav.klage.document.service
33
import no.nav.klage.document.clients.KabalJsonToPdfClient
44
import no.nav.klage.document.domain.Document
55
import no.nav.klage.document.domain.PDFDocument
6+
import no.nav.klage.document.repositories.CommentRepository
67
import no.nav.klage.document.repositories.DocumentRepository
78
import org.springframework.stereotype.Service
89
import org.springframework.transaction.annotation.Transactional
@@ -13,6 +14,7 @@ import java.util.*
1314
@Transactional
1415
class DocumentService(
1516
private val documentRepository: DocumentRepository,
17+
private val commentRepository: CommentRepository,
1618
private val kabalJsonToPdfClient: KabalJsonToPdfClient
1719
) {
1820

@@ -42,4 +44,9 @@ class DocumentService(
4244
return kabalJsonToPdfClient.getPDFDocument(documentRepository.getById(documentId).json)
4345
}
4446

47+
fun deleteDocument(documentId: UUID) {
48+
commentRepository.deleteByDocumentId(documentId)
49+
documentRepository.deleteById(documentId)
50+
}
51+
4552
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ class RepositoryTest {
9393

9494
assertThat(comments.first().comments).hasSize(2)
9595
assertThat(comments.first().comments.first()).isEqualTo(comment2)
96+
97+
commentRepository.deleteByDocumentId(document.id)
98+
documentRepository.deleteById(document.id)
99+
100+
testEntityManager.flush()
101+
testEntityManager.clear()
102+
103+
assertThat(documentRepository.findAll()).isEmpty()
96104
}
97105

98106
}

0 commit comments

Comments
 (0)