11package no.nav.klage.document.api
22
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
37import 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.*
810
911@RestController
10- class DocumentController () {
12+ class DocumentController (
13+ private val documentService : DocumentService ,
14+ private val commentService : CommentService
15+ ) {
1116
1217 companion object {
1318 @Suppress(" JAVA_CLASS_ON_COMPANION" )
@@ -19,37 +24,85 @@ class DocumentController() {
1924 @RequestBody json : String
2025 ): DocumentView {
2126 logger.debug(" createDocument: received json: {}" , json)
22- TODO ( )
27+ return mapToDocumentView(documentService.createDocument(json) )
2328 }
2429
2530 @GetMapping(" /documents/{documentId}" )
26- fun getDocument (): DocumentView {
31+ fun getDocument (@PathVariable( " documentId " ) documentId : UUID ): DocumentView {
2732 logger.debug(" getDocument" )
28- TODO ( )
33+ return mapToDocumentView(documentService.getDocument(documentId) )
2934 }
3035
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+ )
3550 }
3651
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) }
4158 }
4259
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+ )
4776 }
4877
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))
5385 }
5486
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+
55108}
0 commit comments