diff --git a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt index 2c11f49..1681dd0 100644 --- a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt +++ b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt @@ -36,11 +36,11 @@ class DocumentController( ) @PostMapping("") fun createDocument( - @RequestBody json: String + @RequestBody input: DocumentUpdateInput, ): DocumentView { log("createDocument") - secureLogger.debug("createDocument: received json: {}", json) - return mapToDocumentView(documentService.createDocument(json)) + secureLogger.debug("createDocument: received json: {}", input.json) + return mapToDocumentView(documentService.createDocument(json = input.json, data = input.data)) } @Operation( @@ -50,7 +50,7 @@ class DocumentController( @PutMapping("/{documentId}") fun updateDocument( @PathVariable("documentId") documentId: UUID, - @RequestBody(required = false) input: DocumentUpdateInput, + @RequestBody input: DocumentUpdateInput, ): DocumentView { log("updateDocument called with id $documentId") secureLogger.debug( @@ -65,6 +65,7 @@ class DocumentController( documentService.updateDocument( documentId = documentId, json = input.json, + data = input.data, currentVersion = input.currentVersion, ) ) @@ -75,6 +76,7 @@ class DocumentController( documentService.updateDocument( documentId = documentId, json = input.json, + data = input.data, currentVersion = input.currentVersion, ) ) @@ -124,6 +126,7 @@ class DocumentController( documentId = documentVersion.documentId, version = documentVersion.version, json = documentVersion.json, + data = documentVersion.data, authorNavIdent = documentVersion.authorNavIdent, created = documentVersion.created, modified = documentVersion.modified diff --git a/src/main/kotlin/no/nav/klage/document/api/views/DocumentUpdateInput.kt b/src/main/kotlin/no/nav/klage/document/api/views/DocumentUpdateInput.kt index ee2d2b0..350f032 100644 --- a/src/main/kotlin/no/nav/klage/document/api/views/DocumentUpdateInput.kt +++ b/src/main/kotlin/no/nav/klage/document/api/views/DocumentUpdateInput.kt @@ -2,5 +2,6 @@ package no.nav.klage.document.api.views data class DocumentUpdateInput( val json: String, + val data: String?, val currentVersion: Int?, ) \ No newline at end of file diff --git a/src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt b/src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt index 0ddf35c..d1e734a 100644 --- a/src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt +++ b/src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt @@ -5,6 +5,7 @@ import java.util.* data class DocumentView( val json: String, + val data: String?, val documentId: UUID, val id: UUID, val version: Int, diff --git a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt index a8c345a..997ca57 100644 --- a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt +++ b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt @@ -14,6 +14,8 @@ class DocumentVersion( val version: Int, @Column(name = "json") var json: String, + @Column(name = "data") + var data: String?, @Column(name = "created") val created: LocalDateTime, @Column(name = "modified") @@ -38,7 +40,8 @@ class DocumentVersion( } override fun toString(): String { - return "Document(id=$documentId, version=$version, json='$json', created=$created, modified=$modified, authorNavIdent='$authorNavIdent')" + return "DocumentVersion(documentId=$documentId, version=$version, json='$json', data=$data, created=$created, modified=$modified, authorNavIdent='$authorNavIdent')" } + } 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 8ea8b49..046d44c 100644 --- a/src/main/kotlin/no/nav/klage/document/service/CommentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/CommentService.kt @@ -1,6 +1,5 @@ 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 diff --git a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt index 0fffe76..b599aa6 100644 --- a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt @@ -31,7 +31,7 @@ class DocumentService( private val secureLogger = getSecureLogger() } - fun createDocument(json: String): DocumentVersion { + fun createDocument(json: String, data: String?): DocumentVersion { val now = LocalDateTime.now() val document = documentRepository.save( @@ -46,6 +46,7 @@ class DocumentService( documentId = document.id, version = 1, json = json, + data = data, authorNavIdent = tokenUtil.getIdent(), created = now, modified = now, @@ -53,7 +54,7 @@ class DocumentService( ) } - fun updateDocument(documentId: UUID, json: String, currentVersion: Int?): DocumentVersion { + fun updateDocument(documentId: UUID, json: String, data: String?, currentVersion: Int?): DocumentVersion { val now = LocalDateTime.now() val latestVersionNumber = latestDocumentRepository.findById(documentId).get().currentVersion @@ -87,6 +88,7 @@ class DocumentService( documentId = documentVersion.documentId, version = latestVersionNumber + 1, json = json, + data = data, created = now, modified = now, authorNavIdent = tokenUtil.getIdent() diff --git a/src/main/resources/db/migration/V6__Add_data.sql b/src/main/resources/db/migration/V6__Add_data.sql new file mode 100644 index 0000000..de13b41 --- /dev/null +++ b/src/main/resources/db/migration/V6__Add_data.sql @@ -0,0 +1,3 @@ +ALTER TABLE klage.document_version + ADD COLUMN data TEXT +; \ No newline at end of file diff --git a/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt b/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt index 164d3e7..daf1283 100644 --- a/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt +++ b/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt @@ -58,6 +58,7 @@ class RepositoryTest { version = 1, authorNavIdent = "abc", json = "{}", + data = "{}", created = now, modified = now, ) @@ -201,6 +202,7 @@ class RepositoryTest { version = 1, authorNavIdent = "abc", json = "{}", + data = "{}", created = now, modified = now, ) @@ -212,6 +214,7 @@ class RepositoryTest { version = 2, authorNavIdent = "abc", json = "{}", + data = "{}", created = now, modified = now, ) @@ -258,6 +261,7 @@ class RepositoryTest { version = it + 1, authorNavIdent = "abc", json = "{}", + data = "{}", created = now, modified = now, ) @@ -271,6 +275,7 @@ class RepositoryTest { version = it + 1, authorNavIdent = "abc", json = "{}", + data = "{}", created = now, modified = now, )