Skip to content

Commit dbdf12d

Browse files
authored
Merge pull request #190 from navikt/add-data
Added `data`. It's a binary representation of the json that FE needs.
2 parents 1f9abf4 + dbef693 commit dbdf12d

File tree

8 files changed

+25
-8
lines changed

8 files changed

+25
-8
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class DocumentController(
3636
)
3737
@PostMapping("")
3838
fun createDocument(
39-
@RequestBody json: String
39+
@RequestBody input: DocumentUpdateInput,
4040
): DocumentView {
4141
log("createDocument")
42-
secureLogger.debug("createDocument: received json: {}", json)
43-
return mapToDocumentView(documentService.createDocument(json))
42+
secureLogger.debug("createDocument: received json: {}", input.json)
43+
return mapToDocumentView(documentService.createDocument(json = input.json, data = input.data))
4444
}
4545

4646
@Operation(
@@ -50,7 +50,7 @@ class DocumentController(
5050
@PutMapping("/{documentId}")
5151
fun updateDocument(
5252
@PathVariable("documentId") documentId: UUID,
53-
@RequestBody(required = false) input: DocumentUpdateInput,
53+
@RequestBody input: DocumentUpdateInput,
5454
): DocumentView {
5555
log("updateDocument called with id $documentId")
5656
secureLogger.debug(
@@ -65,6 +65,7 @@ class DocumentController(
6565
documentService.updateDocument(
6666
documentId = documentId,
6767
json = input.json,
68+
data = input.data,
6869
currentVersion = input.currentVersion,
6970
)
7071
)
@@ -75,6 +76,7 @@ class DocumentController(
7576
documentService.updateDocument(
7677
documentId = documentId,
7778
json = input.json,
79+
data = input.data,
7880
currentVersion = input.currentVersion,
7981
)
8082
)
@@ -124,6 +126,7 @@ class DocumentController(
124126
documentId = documentVersion.documentId,
125127
version = documentVersion.version,
126128
json = documentVersion.json,
129+
data = documentVersion.data,
127130
authorNavIdent = documentVersion.authorNavIdent,
128131
created = documentVersion.created,
129132
modified = documentVersion.modified

src/main/kotlin/no/nav/klage/document/api/views/DocumentUpdateInput.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ package no.nav.klage.document.api.views
22

33
data class DocumentUpdateInput(
44
val json: String,
5+
val data: String?,
56
val currentVersion: Int?,
67
)

src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.util.*
55

66
data class DocumentView(
77
val json: String,
8+
val data: String?,
89
val documentId: UUID,
910
val id: UUID,
1011
val version: Int,

src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class DocumentVersion(
1414
val version: Int,
1515
@Column(name = "json")
1616
var json: String,
17+
@Column(name = "data")
18+
var data: String?,
1719
@Column(name = "created")
1820
val created: LocalDateTime,
1921
@Column(name = "modified")
@@ -38,7 +40,8 @@ class DocumentVersion(
3840
}
3941

4042
override fun toString(): String {
41-
return "Document(id=$documentId, version=$version, json='$json', created=$created, modified=$modified, authorNavIdent='$authorNavIdent')"
43+
return "DocumentVersion(documentId=$documentId, version=$version, json='$json', data=$data, created=$created, modified=$modified, authorNavIdent='$authorNavIdent')"
4244
}
4345

46+
4447
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package no.nav.klage.document.service
22

3-
import no.nav.klage.document.api.views.CommentView
43
import no.nav.klage.document.domain.Comment
54
import no.nav.klage.document.exceptions.MissingAccessException
65
import no.nav.klage.document.repositories.CommentRepository

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DocumentService(
3131
private val secureLogger = getSecureLogger()
3232
}
3333

34-
fun createDocument(json: String): DocumentVersion {
34+
fun createDocument(json: String, data: String?): DocumentVersion {
3535
val now = LocalDateTime.now()
3636

3737
val document = documentRepository.save(
@@ -46,14 +46,15 @@ class DocumentService(
4646
documentId = document.id,
4747
version = 1,
4848
json = json,
49+
data = data,
4950
authorNavIdent = tokenUtil.getIdent(),
5051
created = now,
5152
modified = now,
5253
)
5354
)
5455
}
5556

56-
fun updateDocument(documentId: UUID, json: String, currentVersion: Int?): DocumentVersion {
57+
fun updateDocument(documentId: UUID, json: String, data: String?, currentVersion: Int?): DocumentVersion {
5758
val now = LocalDateTime.now()
5859
val latestVersionNumber = latestDocumentRepository.findById(documentId).get().currentVersion
5960

@@ -87,6 +88,7 @@ class DocumentService(
8788
documentId = documentVersion.documentId,
8889
version = latestVersionNumber + 1,
8990
json = json,
91+
data = data,
9092
created = now,
9193
modified = now,
9294
authorNavIdent = tokenUtil.getIdent()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE klage.document_version
2+
ADD COLUMN data TEXT
3+
;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class RepositoryTest {
5858
version = 1,
5959
authorNavIdent = "abc",
6060
json = "{}",
61+
data = "{}",
6162
created = now,
6263
modified = now,
6364
)
@@ -201,6 +202,7 @@ class RepositoryTest {
201202
version = 1,
202203
authorNavIdent = "abc",
203204
json = "{}",
205+
data = "{}",
204206
created = now,
205207
modified = now,
206208
)
@@ -212,6 +214,7 @@ class RepositoryTest {
212214
version = 2,
213215
authorNavIdent = "abc",
214216
json = "{}",
217+
data = "{}",
215218
created = now,
216219
modified = now,
217220
)
@@ -258,6 +261,7 @@ class RepositoryTest {
258261
version = it + 1,
259262
authorNavIdent = "abc",
260263
json = "{}",
264+
data = "{}",
261265
created = now,
262266
modified = now,
263267
)
@@ -271,6 +275,7 @@ class RepositoryTest {
271275
version = it + 1,
272276
authorNavIdent = "abc",
273277
json = "{}",
278+
data = "{}",
274279
created = now,
275280
modified = now,
276281
)

0 commit comments

Comments
 (0)