Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/kotlin/no/nav/klage/document/api/DocumentController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -65,6 +65,7 @@ class DocumentController(
documentService.updateDocument(
documentId = documentId,
json = input.json,
data = input.data,
currentVersion = input.currentVersion,
)
)
Expand All @@ -75,6 +76,7 @@ class DocumentController(
documentService.updateDocument(
documentId = documentId,
json = input.json,
data = input.data,
currentVersion = input.currentVersion,
)
)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package no.nav.klage.document.api.views

data class DocumentUpdateInput(
val json: String,
val data: String?,
val currentVersion: Int?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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')"
}


}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -46,14 +46,15 @@ class DocumentService(
documentId = document.id,
version = 1,
json = json,
data = data,
authorNavIdent = tokenUtil.getIdent(),
created = now,
modified = now,
)
)
}

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

Expand Down Expand Up @@ -87,6 +88,7 @@ class DocumentService(
documentId = documentVersion.documentId,
version = latestVersionNumber + 1,
json = json,
data = data,
created = now,
modified = now,
authorNavIdent = tokenUtil.getIdent()
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/db/migration/V6__Add_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE klage.document_version
ADD COLUMN data TEXT
;
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class RepositoryTest {
version = 1,
authorNavIdent = "abc",
json = "{}",
data = "{}",
created = now,
modified = now,
)
Expand Down Expand Up @@ -201,6 +202,7 @@ class RepositoryTest {
version = 1,
authorNavIdent = "abc",
json = "{}",
data = "{}",
created = now,
modified = now,
)
Expand All @@ -212,6 +214,7 @@ class RepositoryTest {
version = 2,
authorNavIdent = "abc",
json = "{}",
data = "{}",
created = now,
modified = now,
)
Expand Down Expand Up @@ -258,6 +261,7 @@ class RepositoryTest {
version = it + 1,
authorNavIdent = "abc",
json = "{}",
data = "{}",
created = now,
modified = now,
)
Expand All @@ -271,6 +275,7 @@ class RepositoryTest {
version = it + 1,
authorNavIdent = "abc",
json = "{}",
data = "{}",
created = now,
modified = now,
)
Expand Down