-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessController.kt
70 lines (51 loc) · 1.9 KB
/
ProcessController.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.jeske.restapiwithopenai.controller
import de.jeske.restapiwithopenai.dtos.IdeaDTO
import de.jeske.restapiwithopenai.dtos.ProcessDTO
import de.jeske.restapiwithopenai.dtos.QuestionDTO
import de.jeske.restapiwithopenai.dtos.ResponseDTO
import de.jeske.restapiwithopenai.modells.Idea
import de.jeske.restapiwithopenai.modells.Question
import de.jeske.restapiwithopenai.services.ProcessService
import org.bson.types.ObjectId
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/process")
class ProcessController {
@Autowired
private lateinit var processService: ProcessService
@GetMapping
fun getProcess(
@RequestParam id: String
) : ProcessDTO {
val processId = ObjectId(id)
val process = processService.getProcessById(processId)
return ProcessDTO(process)
}
@PostMapping("/start")
suspend fun startProcess(
@RequestParam id: String,
@RequestParam lang: String
) : QuestionDTO {
val userId = ObjectId(id)
val question = processService.startProcess(userId, lang)
return QuestionDTO(question)
}
@PostMapping("/response")
suspend fun response(
@RequestParam id: String,
@RequestParam choice: String
) : ResponseDTO {
val processId = ObjectId(id)
val response = processService.continueProcess(processId, choice)
return when (response) {
is Idea -> IdeaDTO(response)
is Question -> QuestionDTO(response)
else -> throw TypeNotPresentException("response", null)
}
}
}