Skip to content

Commit e82e4d5

Browse files
committed
Added comments and basic API
1 parent f43116d commit e82e4d5

File tree

7 files changed

+143
-7
lines changed

7 files changed

+143
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package no.nav.klage.document.api
2+
3+
import java.time.LocalDateTime
4+
import java.util.*
5+
6+
data class CommentView(
7+
val id: UUID,
8+
val text: String,
9+
val created: LocalDateTime,
10+
val modified: LocalDateTime
11+
)

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.nav.klage.document.api
22

33
import no.nav.klage.document.util.getLogger
4+
import org.springframework.web.bind.annotation.GetMapping
45
import org.springframework.web.bind.annotation.PostMapping
56
import org.springframework.web.bind.annotation.RequestBody
67
import org.springframework.web.bind.annotation.RestController
@@ -21,4 +22,34 @@ class DocumentController() {
2122
TODO()
2223
}
2324

25+
@GetMapping("/documents/{documentId}")
26+
fun getDocument(): DocumentView {
27+
logger.debug("getDocument")
28+
TODO()
29+
}
30+
31+
@PostMapping("/documents/{documentId}/commentthreads")
32+
fun createCommentThread() {
33+
logger.debug("createCommentThread")
34+
TODO()
35+
}
36+
37+
@GetMapping("/documents/{documentId}/commentthreads")
38+
fun getAllThreadsWithComments() {
39+
logger.debug("getAllThreadsWithComments")
40+
TODO()
41+
}
42+
43+
@PostMapping("/documents/{documentId}/commentthreads/{threadId}")
44+
fun createCommentInThread() {
45+
logger.debug("createCommentInThread")
46+
TODO()
47+
}
48+
49+
@GetMapping("/documents/{documentId}/commentthreads/{threadId}")
50+
fun getCommentsInThread() {
51+
logger.debug("getCommentsInThread")
52+
TODO()
53+
}
54+
2455
}

src/main/kotlin/no/nav/klage/document/api/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 id: UUID,
8+
val json: String,
89
val created: LocalDateTime,
910
val modified: LocalDateTime
1011
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package no.nav.klage.document.domain
2+
3+
import java.time.LocalDateTime
4+
import java.util.*
5+
import javax.persistence.Column
6+
import javax.persistence.Entity
7+
import javax.persistence.Id
8+
import javax.persistence.Table
9+
10+
@Entity
11+
@Table(name = "document_comment", schema = "klage")
12+
class Comment(
13+
@Id
14+
val id: UUID = UUID.randomUUID(),
15+
@Column(name = "document_id")
16+
var documentId: UUID,
17+
@Column(name = "text")
18+
var text: String,
19+
@Column(name = "created")
20+
val created: LocalDateTime,
21+
@Column(name = "modified")
22+
var modified: LocalDateTime
23+
) {
24+
override fun equals(other: Any?): Boolean {
25+
if (this === other) return true
26+
if (javaClass != other?.javaClass) return false
27+
28+
other as Comment
29+
30+
if (id != other.id) return false
31+
32+
return true
33+
}
34+
35+
override fun hashCode(): Int {
36+
return id.hashCode()
37+
}
38+
39+
override fun toString(): String {
40+
return "Comment(id=$id, documentId=$documentId, text='$text', created=$created, modified=$modified)"
41+
}
42+
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package no.nav.klage.document.repositories
2+
3+
import no.nav.klage.document.domain.Comment
4+
import org.springframework.data.jpa.repository.JpaRepository
5+
import java.util.*
6+
7+
interface CommentRepository : JpaRepository<Comment, UUID> {
8+
9+
fun findByDocumentId(documentId: UUID): List<Comment>
10+
11+
}

src/main/resources/db/migration/V1__Create_baseline.sql

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ $$;
1616

1717
CREATE TABLE klage.document
1818
(
19-
id UUID PRIMARY KEY,
20-
json TEXT NOT NULL,
21-
created TIMESTAMP NOT NULL,
22-
modified TIMESTAMP NOT NULL
23-
);
19+
id UUID PRIMARY KEY,
20+
json TEXT NOT NULL,
21+
created TIMESTAMP NOT NULL,
22+
modified TIMESTAMP NOT NULL
23+
);
24+
25+
CREATE TABLE klage.document_comment
26+
(
27+
id UUID PRIMARY KEY,
28+
document_id UUID REFERENCES klage.document (id),
29+
text TEXT NOT NULL,
30+
created TIMESTAMP NOT NULL,
31+
modified TIMESTAMP NOT NULL
32+
);
33+
34+
CREATE INDEX document_comment_ix ON klage.document_comment (document_id);

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.klage.document.repositories
22

3+
import no.nav.klage.document.domain.Comment
34
import no.nav.klage.document.domain.Document
45
import org.assertj.core.api.Assertions.assertThat
56
import org.junit.jupiter.api.Test
@@ -16,7 +17,7 @@ import java.time.LocalDateTime
1617
@DataJpaTest
1718
@Testcontainers
1819
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
19-
class DocumentRepositoryTest {
20+
class RepositoryTest {
2021

2122
companion object {
2223
@Container
@@ -30,8 +31,11 @@ class DocumentRepositoryTest {
3031
@Autowired
3132
lateinit var documentRepository: DocumentRepository
3233

34+
@Autowired
35+
lateinit var commentRepository: CommentRepository
36+
3337
@Test
34-
fun `add documents works`() {
38+
fun `add document and comments work`() {
3539

3640
val now = LocalDateTime.now()
3741

@@ -48,6 +52,30 @@ class DocumentRepositoryTest {
4852

4953
val foundDocument = documentRepository.findById(document.id).get()
5054
assertThat(foundDocument).isEqualTo(document)
55+
56+
val comment1 = Comment(
57+
documentId = document.id,
58+
text = "my comment 1",
59+
created = now.plusDays(1),
60+
modified = now.plusDays(1)
61+
)
62+
63+
val comment2 = Comment(
64+
documentId = document.id,
65+
text = "my comment 2",
66+
created = now.plusDays(2),
67+
modified = now.plusDays(2)
68+
)
69+
70+
commentRepository.save(comment1)
71+
commentRepository.save(comment2)
72+
73+
testEntityManager.flush()
74+
testEntityManager.clear()
75+
76+
val comments = commentRepository.findByDocumentId(document.id)
77+
78+
assertThat(comments).hasSize(2)
5179
}
5280

5381
}

0 commit comments

Comments
 (0)