Код: Выделить всё
@GetMapping("/{userId}")
fun getOneUser(@PathVariable userId: UserId): Mono {
return repository.findById(userId)
.map(User::asDto)
.map { ResponseEntity.ok(it) }
.defaultIfEmpty(ResponseEntity.notFound().build())
}
@GetMapping
fun getAllUsers(): Flux {
return repository.findAllActive().map(User::asDto)
}
Например:
Код: Выделить всё
@GetMapping("/{userId}/options")
fun getAllUserOptions(@PathVariable userId: UserId): ??? {
return repository.findById(userId)
.flatMapIterable{ it.options }
.map { OptionDto.from(it) }
// if findById -> empty Mono then:
// return ResponseEntity.notFound().build() ?
// else:
// return the result of `.map { OptionDto.from(it) }` ?
}
code>, в противном случае верните user.options как Flux.
Обновление:
здесь репозиторий ReactiveCrudRepository
Подробнее здесь: https://stackoverflow.com/questions/524 ... ontrollers