Skip to content

Commit 01fa047

Browse files
committed
AKTLN-587 reformated the code
1 parent 922d864 commit 01fa047

File tree

9 files changed

+142
-142
lines changed

9 files changed

+142
-142
lines changed

kotlin-dsl/src/main/kotlin/com/baeldung/functional_dsl/bean_declaration/BeanDeclration.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import org.springframework.context.support.beans
1010
open class Application
1111

1212
fun main(vararg args: String) {
13-
runApplication<Application>(*args) {
14-
addInitializers(
15-
beans {
16-
bean(
17-
name = "functionallyDeclaredBean",
18-
scope = BeanDefinitionDsl.Scope.SINGLETON,
19-
isLazyInit = false,
20-
isPrimary = false,
21-
function = {
22-
BigDecimal(1.0)
23-
}
13+
runApplication<Application>(*args) {
14+
addInitializers(
15+
beans {
16+
bean(
17+
name = "functionallyDeclaredBean",
18+
scope = BeanDefinitionDsl.Scope.SINGLETON,
19+
isLazyInit = false,
20+
isPrimary = false,
21+
function = {
22+
BigDecimal(1.0)
23+
}
24+
)
25+
}
2426
)
25-
}
26-
)
27-
}
27+
}
2828
}

kotlin-dsl/src/main/kotlin/com/baeldung/functional_dsl/regular_controller/RegularController.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import org.springframework.web.bind.annotation.RestController
1111
@RestController
1212
class RegularController {
1313

14-
@GetMapping(path = ["/endpoint/{country}"])
15-
fun getPerson(
16-
@RequestParam name: String,
17-
@RequestHeader(name = "X-age") age: String,
18-
@PathVariable country: String
19-
) : Map<*, *> {
20-
return mapOf(
21-
"name" to name,
22-
"age" to age,
23-
"country" to country
24-
)
25-
}
14+
@GetMapping(path = ["/endpoint/{country}"])
15+
fun getPerson(
16+
@RequestParam name: String,
17+
@RequestHeader(name = "X-age") age: String,
18+
@PathVariable country: String
19+
): Map<*, *> {
20+
return mapOf(
21+
"name" to name,
22+
"age" to age,
23+
"country" to country
24+
)
25+
}
2626
}

kotlin-dsl/src/main/kotlin/com/baeldung/functional_dsl/router_function/RouterFunction.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import org.springframework.web.servlet.function.ServerResponse
1111
@SpringBootApplication
1212
open class Application {
1313

14-
@Bean
15-
open fun configure() : RouterFunction<ServerResponse> {
16-
return RouterFunctions.route()
17-
.GET("/endpoint/{country}") {
18-
ServerResponse.ok().body(
19-
mapOf(
20-
"name" to it.param("name"),
21-
"age" to it.headers().header("X-age")[0],
22-
"country" to it.pathVariable("country")
23-
)
24-
)
25-
}
26-
.build()
27-
}
14+
@Bean
15+
open fun configure(): RouterFunction<ServerResponse> {
16+
return RouterFunctions.route()
17+
.GET("/endpoint/{country}") {
18+
ServerResponse.ok().body(
19+
mapOf(
20+
"name" to it.param("name"),
21+
"age" to it.headers().header("X-age")[0],
22+
"country" to it.pathVariable("country")
23+
)
24+
)
25+
}
26+
.build()
27+
}
2828
}
2929

3030
fun main(vararg args: String) {
31-
runApplication<Application>(*args)
31+
runApplication<Application>(*args)
3232
}

kotlin-dsl/src/main/kotlin/com/baeldung/functional_dsl/router_function_dsl/RouterDsl.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ import org.springframework.web.servlet.function.router
1111
open class Application
1212

1313
fun main(vararg args: String) {
14-
runApplication<Application>(*args)
15-
{
16-
addInitializers(
17-
beans {
18-
bean {
19-
router {
20-
GET("/endpoint/{country}") { it : ServerRequest ->
21-
ServerResponse.ok().body(
22-
mapOf(
23-
"name" to it.param("name"),
24-
"age" to it.headers().header("X-age")[0],
25-
"country" to it.pathVariable("country")
26-
)
27-
)
14+
runApplication<Application>(*args)
15+
{
16+
addInitializers(
17+
beans {
18+
bean {
19+
router {
20+
GET("/endpoint/{country}") { it: ServerRequest ->
21+
ServerResponse.ok().body(
22+
mapOf(
23+
"name" to it.param("name"),
24+
"age" to it.headers().header("X-age")[0],
25+
"country" to it.pathVariable("country")
26+
)
27+
)
28+
}
29+
}
30+
}
2831
}
29-
}
30-
}
31-
}
32-
)
33-
}
32+
)
33+
}
3434
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.baeldung.functional_dsl
22

33
class User(
4-
var userId: Long,
5-
var name: String,
6-
var age: Int,
7-
var country: String,
4+
var userId: Long,
5+
var name: String,
6+
var age: Int,
7+
var country: String,
88
)

kotlin-reactive-dsl/src/main/kotlin/com/baeldung/functional_dsl/UsersRepository.kt

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ import reactor.core.publisher.Mono
1010
@Component
1111
class UsersRepository {
1212

13-
private val userStorage: MutableMap<Long, User>
13+
private val userStorage: MutableMap<Long, User>
1414

15-
init {
16-
userStorage = mutableMapOf(
17-
1L to User(1L, "Alex", 18, "Malta"),
18-
2L to User(2L, "Eugen", 36, "Austria"),
19-
3L to User(3L, "Jenny", 12, "Canada")
20-
)
21-
}
15+
init {
16+
userStorage = mutableMapOf(
17+
1L to User(1L, "Alex", 18, "Malta"),
18+
2L to User(2L, "Eugen", 36, "Austria"),
19+
3L to User(3L, "Jenny", 12, "Canada")
20+
)
21+
}
2222

23-
fun findUserById(id: Long) : Mono<User> {
24-
return Mono
25-
.fromCallable { userStorage[id] }
26-
.handle { value, sink ->
27-
if (value == null) {
28-
sink.error(IllegalArgumentException())
29-
} else {
30-
sink.next(value)
31-
}
32-
}
33-
}
23+
fun findUserById(id: Long): Mono<User> {
24+
return Mono
25+
.fromCallable { userStorage[id] }
26+
.handle { value, sink ->
27+
if (value == null) {
28+
sink.error(IllegalArgumentException())
29+
} else {
30+
sink.next(value)
31+
}
32+
}
33+
}
3434

35-
fun createUsers(user: Mono<User>) {
36-
user.doOnNext {
37-
userStorage[it.userId] = it
38-
}.subscribe()
39-
}
35+
fun createUsers(user: Mono<User>) {
36+
user.doOnNext {
37+
userStorage[it.userId] = it
38+
}.subscribe()
39+
}
4040

41-
suspend fun findUserByIdForCoroutines(id: Long) : Flow<User> {
42-
return flow {
43-
val user = userStorage[id] ?: User(0L, "Name", 0, "USA")
44-
emit(user)
41+
suspend fun findUserByIdForCoroutines(id: Long): Flow<User> {
42+
return flow {
43+
val user = userStorage[id] ?: User(0L, "Name", 0, "USA")
44+
emit(user)
45+
}
4546
}
46-
}
4747
}

kotlin-reactive-dsl/src/main/kotlin/com/baeldung/functional_dsl/coroutines/CoroutinesConfig.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ import org.springframework.web.reactive.function.server.coRouter
1616
@SpringBootApplication
1717
open class AppCoroutines {
1818

19-
@Autowired
20-
private lateinit var usersRepository: UsersRepository
19+
@Autowired
20+
private lateinit var usersRepository: UsersRepository
2121

22-
@Bean
23-
open fun registerForCo() =
24-
coRouter {
25-
GET("/users/{id}") {
26-
println("here we are!")
27-
val customers : Flow<User> = usersRepository.findUserByIdForCoroutines(
28-
it.pathVariable("id").toLong()
29-
)
30-
ServerResponse.ok().bodyAndAwait(customers)
31-
}
32-
}
22+
@Bean
23+
open fun registerForCo() =
24+
coRouter {
25+
GET("/users/{id}") {
26+
println("here we are!")
27+
val customers: Flow<User> = usersRepository.findUserByIdForCoroutines(
28+
it.pathVariable("id").toLong()
29+
)
30+
ServerResponse.ok().bodyAndAwait(customers)
31+
}
32+
}
3333
}
3434

3535
fun main(vararg args: String) {
36-
runApplication<AppCoroutines>(*args) {}
36+
runApplication<AppCoroutines>(*args) {}
3737
}

kotlin-reactive-dsl/src/main/kotlin/com/baeldung/functional_dsl/router_function/ReactiveConfig.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ import org.springframework.web.reactive.function.server.router
1717
@SpringBootApplication
1818
open class ReactiveConfig {
1919

20-
@Autowired
21-
private lateinit var usersRepository: UsersRepository
20+
@Autowired
21+
private lateinit var usersRepository: UsersRepository
2222

23-
@Bean
24-
open fun configure() : RouterFunction<ServerResponse> {
25-
return RouterFunctions.route()
26-
.GET("/users/{id}") {
27-
ServerResponse
28-
.ok()
29-
.body(usersRepository.findUserById(it.pathVariable("id").toLong()))
30-
}
31-
.POST("/create") {
32-
usersRepository.createUsers(it.bodyToMono(User::class.java))
33-
return@POST ServerResponse
34-
.ok()
35-
.build()
36-
}
37-
.build()
38-
}
23+
@Bean
24+
open fun configure(): RouterFunction<ServerResponse> {
25+
return RouterFunctions.route()
26+
.GET("/users/{id}") {
27+
ServerResponse
28+
.ok()
29+
.body(usersRepository.findUserById(it.pathVariable("id").toLong()))
30+
}
31+
.POST("/create") {
32+
usersRepository.createUsers(it.bodyToMono(User::class.java))
33+
return@POST ServerResponse
34+
.ok()
35+
.build()
36+
}
37+
.build()
38+
}
3939
}
4040

4141
fun main(vararg args: String) {
42-
runApplication<ReactiveConfig>(*args) {}
42+
runApplication<ReactiveConfig>(*args) {}
4343
}

kotlin-reactive-dsl/src/main/kotlin/com/baeldung/functional_dsl/router_function_dsl/ReactiveDslConfig.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ import org.springframework.web.reactive.function.server.router
1717
@SpringBootApplication
1818
open class ReactiveDslConfig {
1919

20-
@Autowired
21-
private lateinit var usersRepository: UsersRepository
20+
@Autowired
21+
private lateinit var usersRepository: UsersRepository
2222

23-
@Bean
24-
open fun endpoints() = router {
25-
GET("/users/{id}") {
26-
ServerResponse
27-
.ok()
28-
.body(usersRepository.findUserById(it.pathVariable("id").toLong()))
29-
}
23+
@Bean
24+
open fun endpoints() = router {
25+
GET("/users/{id}") {
26+
ServerResponse
27+
.ok()
28+
.body(usersRepository.findUserById(it.pathVariable("id").toLong()))
29+
}
3030

31-
POST("/create") {
32-
usersRepository.createUsers(it.bodyToMono(User::class.java))
33-
return@POST ServerResponse
34-
.ok()
35-
.build()
31+
POST("/create") {
32+
usersRepository.createUsers(it.bodyToMono(User::class.java))
33+
return@POST ServerResponse
34+
.ok()
35+
.build()
36+
}
3637
}
37-
}
3838
}
3939

4040
fun main(vararg args: String) {
41-
runApplication<ReactiveDslConfig>(*args) {}
41+
runApplication<ReactiveDslConfig>(*args) {}
4242
}

0 commit comments

Comments
 (0)