1
1
package no.nav.klage.document.api
2
2
3
+ import no.nav.klage.document.domain.Comment
4
+ import no.nav.klage.document.domain.Document
5
+ import no.nav.klage.document.service.CommentService
6
+ import no.nav.klage.document.service.DocumentService
3
7
import no.nav.klage.document.util.getLogger
4
- import org.springframework.web.bind.annotation.GetMapping
5
- import org.springframework.web.bind.annotation.PostMapping
6
- import org.springframework.web.bind.annotation.RequestBody
7
- import org.springframework.web.bind.annotation.RestController
8
+ import org.springframework.web.bind.annotation.*
9
+ import java.util.*
8
10
9
11
@RestController
10
- class DocumentController () {
12
+ class DocumentController (
13
+ private val documentService : DocumentService ,
14
+ private val commentService : CommentService
15
+ ) {
11
16
12
17
companion object {
13
18
@Suppress(" JAVA_CLASS_ON_COMPANION" )
@@ -19,37 +24,85 @@ class DocumentController() {
19
24
@RequestBody json : String
20
25
): DocumentView {
21
26
logger.debug(" createDocument: received json: {}" , json)
22
- TODO ( )
27
+ return mapToDocumentView(documentService.createDocument(json) )
23
28
}
24
29
25
30
@GetMapping(" /documents/{documentId}" )
26
- fun getDocument (): DocumentView {
31
+ fun getDocument (@PathVariable( " documentId " ) documentId : UUID ): DocumentView {
27
32
logger.debug(" getDocument" )
28
- TODO ( )
33
+ return mapToDocumentView(documentService.getDocument(documentId) )
29
34
}
30
35
31
- @PostMapping(" /documents/{documentId}/commentthreads" )
32
- fun createCommentThread () {
33
- logger.debug(" createCommentThread" )
34
- TODO ()
36
+ @PostMapping(" /documents/{documentId}/comments" )
37
+ fun createComment (
38
+ @PathVariable(" documentId" ) documentId : UUID ,
39
+ @RequestBody commentInput : CommentInput
40
+ ): CommentView {
41
+ logger.debug(" createComment" )
42
+ return mapCommentToView(
43
+ commentService.createComment(
44
+ documentId = documentId,
45
+ text = commentInput.text,
46
+ authorName = commentInput.author.name,
47
+ authorIdent = commentInput.author.ident
48
+ )
49
+ )
35
50
}
36
51
37
- @GetMapping(" /documents/{documentId}/commentthreads" )
38
- fun getAllThreadsWithComments () {
39
- logger.debug(" getAllThreadsWithComments" )
40
- TODO ()
52
+ @GetMapping(" /documents/{documentId}/comments" )
53
+ fun getAllCommentsWithPossibleThreads (
54
+ @PathVariable(" documentId" ) documentId : UUID
55
+ ): List <CommentView > {
56
+ logger.debug(" getAllCommentsWithPossibleThreads" )
57
+ return commentService.getComments(documentId).map { mapCommentToView(it) }
41
58
}
42
59
43
- @PostMapping(" /documents/{documentId}/commentthreads/{threadId}" )
44
- fun createCommentInThread () {
45
- logger.debug(" createCommentInThread" )
46
- TODO ()
60
+ @PostMapping(" /documents/{documentId}/comments/{commentId}" )
61
+ fun replyToComment (
62
+ @PathVariable(" documentId" ) documentId : UUID ,
63
+ @PathVariable(" commentId" ) commentId : UUID ,
64
+ @RequestBody commentInput : CommentInput ,
65
+ ): CommentView {
66
+ logger.debug(" replyToComment" )
67
+ return mapCommentToView(
68
+ commentService.replyToComment(
69
+ documentId = documentId,
70
+ parentCommentId = commentId,
71
+ text = commentInput.text,
72
+ authorName = commentInput.author.name,
73
+ authorIdent = commentInput.author.ident
74
+ )
75
+ )
47
76
}
48
77
49
- @GetMapping(" /documents/{documentId}/commentthreads/{threadId}" )
50
- fun getCommentsInThread () {
51
- logger.debug(" getCommentsInThread" )
52
- TODO ()
78
+ @GetMapping(" /documents/{documentId}/comments/{commentId}" )
79
+ fun getCommentWithPossibleThread (
80
+ @PathVariable(" documentId" ) documentId : UUID ,
81
+ @PathVariable(" commentId" ) commentId : UUID
82
+ ): CommentView {
83
+ logger.debug(" getCommentWithPossibleThread" )
84
+ return mapCommentToView(commentService.getComment(commentId = commentId))
53
85
}
54
86
87
+ private fun mapToDocumentView (document : Document ): DocumentView =
88
+ DocumentView (
89
+ id = document.id,
90
+ json = document.json,
91
+ created = document.created,
92
+ modified = document.modified
93
+ )
94
+
95
+ private fun mapCommentToView (comment : Comment ): CommentView =
96
+ CommentView (
97
+ id = comment.id,
98
+ text = comment.text,
99
+ author = CommentView .Author (
100
+ name = comment.authorName,
101
+ ident = comment.authorIdent
102
+ ),
103
+ comments = comment.comments.map { mapCommentToView(it) },
104
+ created = comment.created,
105
+ modified = comment.modified
106
+ )
107
+
55
108
}
0 commit comments