@@ -26,7 +26,7 @@ class TodoHandler(val repository: TodoRepository) {
2626
2727 suspend fun findAllByStatus (request : ServerRequest ): ServerResponse = coroutineScope {
2828 return @coroutineScope runCatching {
29- var status = request.queryParam(" status" ).map { it.toBoolean() }.orElse(false )
29+ val status = request.queryParam(" status" ).map { it.toBoolean() }.orElse(false )
3030 val page = request.queryParam(" page" ).map { it.toInt() }.orElse(0 )
3131 val size = request.queryParam(" size" ).map { it.toInt() }.orElse(10 )
3232 val sort = Sort .by(listOf (Sort .Order .desc(" id" )))
@@ -38,39 +38,39 @@ class TodoHandler(val repository: TodoRepository) {
3838 }
3939 repository.findAllByStatusEquals(status, paging)
4040 }.fold(
41- onSuccess = {
42- ok().contentType(APPLICATION_JSON ).bodyAndAwait(it);
43- },
44- onFailure = {
45- log.error(it.message)
46- status(HttpStatus .INTERNAL_SERVER_ERROR )
47- .contentType(APPLICATION_JSON )
48- .bodyAndAwait(flowOf(listOf<Todo >()))
49- }
41+ onSuccess = {
42+ ok().contentType(APPLICATION_JSON ).bodyAndAwait(it);
43+ },
44+ onFailure = {
45+ log.error(it.message)
46+ status(HttpStatus .INTERNAL_SERVER_ERROR )
47+ .contentType(APPLICATION_JSON )
48+ .bodyAndAwait(flowOf(listOf<Todo >()))
49+ }
5050 )
5151 }
5252
5353 suspend fun findById (request : ServerRequest ): ServerResponse = coroutineScope {
5454 val id = request.pathVariable(" id" ).toLong()
5555 val todo = id.let { repository.findById(id) }
5656 return @coroutineScope todo?.let { ok().contentType(APPLICATION_JSON ).bodyValueAndAwait(it) }
57- ? : ServerResponse .notFound().buildAndAwait()
57+ ? : ServerResponse .notFound().buildAndAwait()
5858 }
5959
6060 suspend fun edit (request : ServerRequest ): ServerResponse = coroutineScope {
6161 return @coroutineScope runCatching {
6262 val todo = request.awaitBody<Todo >()
6363 repository.save(todo)
6464 }.fold(
65- onSuccess = {
66- ok().contentType(APPLICATION_JSON ).bodyAndAwait(flowOf(it));
67- },
68- onFailure = {
69- log.error(it.message)
70- status(HttpStatus .NOT_FOUND )
71- .contentType(APPLICATION_JSON )
72- .bodyAndAwait(flowOf(Todo (id = 0L , task = " " , status = false )))
73- }
65+ onSuccess = {
66+ ok().contentType(APPLICATION_JSON ).bodyAndAwait(flowOf(it));
67+ },
68+ onFailure = {
69+ log.error(it.message)
70+ status(HttpStatus .NOT_FOUND )
71+ .contentType(APPLICATION_JSON )
72+ .bodyAndAwait(flowOf(Todo (id = 0L , task = " " , status = false )))
73+ }
7474 )
7575 }
7676
@@ -79,15 +79,15 @@ class TodoHandler(val repository: TodoRepository) {
7979 val id = request.pathVariable(" id" ).toLong()
8080 repository.deleteById(id)
8181 }.fold(
82- onSuccess = {
83- ok().contentType(APPLICATION_JSON ).bodyAndAwait(flowOf(it));
84- },
85- onFailure = {
86- log.error(it.message)
87- status(HttpStatus .INTERNAL_SERVER_ERROR )
88- .contentType(APPLICATION_JSON )
89- .bodyAndAwait(flowOf(Todo (id = 0L , task = " " , status = false )))
90- }
82+ onSuccess = {
83+ ok().contentType(APPLICATION_JSON ).bodyAndAwait(flowOf(it));
84+ },
85+ onFailure = {
86+ log.error(it.message)
87+ status(HttpStatus .INTERNAL_SERVER_ERROR )
88+ .contentType(APPLICATION_JSON )
89+ .bodyAndAwait(flowOf(Todo (id = 0L , task = " " , status = false )))
90+ }
9191 )
9292 }
9393
0 commit comments