-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainController.kt
48 lines (40 loc) · 1.6 KB
/
MainController.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
package com.dddeurope.recycle.spring
import com.dddeurope.recycle.domain.PriceCalculator
import com.dddeurope.recycle.events.EventMessage
import com.dddeurope.recycle.events.PriceWasCalculated
import mu.KLogging
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.*
@RestController
@RequestMapping("/")
class MainController {
companion object : KLogging()
@GetMapping("/")
fun home(): String =
"please enter a public URL to this site on https://domainmodelling.dev, as specified in the readme"
@GetMapping("/validate")
fun validate(): String = "Hi!"
@PostMapping("/handle-command")
fun handle(@RequestBody request: RecycleRequest): ResponseEntity<EventMessage> {
logger.info("Incoming Request: {}", request.asString())
// If you have no inspiration to start implementing, uncomment this part:
// val calculator = PriceCalculator(*request.getEvents().toTypedArray())
// val amount = request.toCalculatePriceCommand().let {
// calculator.calculatePrice(it.cardId)
// }
//
// return ResponseEntity.ok(
// EventMessage(
// eventId = UUID.randomUUID().toString(),
// payload = PriceWasCalculated("123", amount, "EUR")
// )
// )
return ResponseEntity.ok(
EventMessage(
eventId = UUID.randomUUID().toString(),
payload = PriceWasCalculated("123", 1.0, "EUR")
)
)
}
}