Skip to content

Commit a6a9c08

Browse files
committed
Applied ktlint for spring-reactive-kotlin module
1 parent dd372d1 commit a6a9c08

File tree

29 files changed

+162
-194
lines changed

29 files changed

+162
-194
lines changed

kotlin-dsl/src/test/java/com/baeldung/functionaldsl/regularcontroller/RegularControllerUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class RegularControllerUnitTest {
2424
private ObjectMapper objectMapper = new ObjectMapper();
2525

2626
@Test
27-
void test() throws Exception {
27+
void whenGetOnRouterEndpoint_thenCorrectResponseReturned() throws Exception {
2828
Map<String, Object> result = objectMapper.readValue(mockMvc
2929
.perform(get("/endpoint/anything").header("X-age", 22).param("name", "Mikhail"))
3030
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())

kotlin-dsl/src/test/java/com/baeldung/functionaldsl/router_function/RouterFunctionUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class RouterFunctionUnitTest {
2424
private ObjectMapper objectMapper = new ObjectMapper();
2525

2626
@Test
27-
void test() throws Exception {
27+
void whenGetOnRouterEndpoint_thenCorrectResponseReturned() throws Exception {
2828
Map<String, Object> result = objectMapper.readValue(mockMvc
2929
.perform(get("/endpoint/anything").header("X-age", 22).param("name", "Mikhail"))
3030
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())

kotlin-dsl/src/test/java/com/baeldung/functionaldsl/routerfunctiondsl/RouterDslUnitTest.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import org.springframework.boot.runApplication
77
class HealthTrackerApplication
88

99
fun main(args: Array<String>) {
10-
runApplication<HealthTrackerApplication>(*args)
10+
runApplication<HealthTrackerApplication>(*args)
1111
}

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
package com.baeldung.bootmicroservice.config;
1+
package com.baeldung.bootmicroservice.config
22

33
import org.springframework.context.annotation.Configuration
44
import org.springframework.r2dbc.core.DatabaseClient
55

66
@Configuration
77
class DBConfiguration(db: DatabaseClient) {
88
init {
9-
val initDb = db.sql {
10-
""" CREATE TABLE IF NOT EXISTS profile (
9+
val initDb =
10+
db.sql {
11+
""" CREATE TABLE IF NOT EXISTS profile (
1112
id SERIAL PRIMARY KEY,
1213
first_name VARCHAR(20) NOT NULL,
1314
last_name VARCHAR(20) NOT NULL,
@@ -22,7 +23,7 @@ class DBConfiguration(db: DatabaseClient) {
2223
date DATE NOT NULL
2324
);
2425
"""
25-
}
26+
}
2627
initDb.then().subscribe()
2728
}
2829
}

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,34 @@ import reactor.core.publisher.Mono
1212

1313
@RestController
1414
class HealthRecordController(val repository: HealthRecordRepository) {
15-
1615
@PostMapping("/health/{profileId}/record")
17-
fun storeHealthRecord(@PathVariable("profileId") profileId: Long, @RequestBody record: HealthRecord): Mono<HealthRecord> =
18-
repository.save(HealthRecord(null
19-
, profileId
20-
, record.temperature
21-
, record.bloodPressure
22-
, record.heartRate
23-
, record.date))
16+
fun storeHealthRecord(
17+
@PathVariable("profileId") profileId: Long,
18+
@RequestBody record: HealthRecord,
19+
): Mono<HealthRecord> =
20+
repository.save(HealthRecord(null, profileId, record.temperature, record.bloodPressure, record.heartRate, record.date))
2421

2522
@GetMapping("/health/{profileId}/avg")
26-
fun fetchHealthRecordAverage(@PathVariable("profileId") profileId: Long): Mono<AverageHealthStatus> =
27-
repository.findByProfileId(profileId)
28-
.reduce(
29-
AverageHealthStatus(0, 0.0, 0.0, 0.0)
30-
, { s, r ->
31-
AverageHealthStatus(s.cnt + 1
32-
, s.temperature + r.temperature
33-
, s.bloodPressure + r.bloodPressure
34-
, s.heartRate + r.heartRate
35-
)
36-
}
37-
).map { s ->
38-
AverageHealthStatus(s.cnt
39-
, if (s.cnt != 0) s.temperature / s.cnt else 0.0
40-
, if (s.cnt != 0) s.bloodPressure / s.cnt else 0.0
41-
, if (s.cnt != 0) s.heartRate / s.cnt else 0.0)
42-
}
43-
44-
}
23+
fun fetchHealthRecordAverage(
24+
@PathVariable("profileId") profileId: Long,
25+
): Mono<AverageHealthStatus> =
26+
repository.findByProfileId(profileId)
27+
.reduce(
28+
AverageHealthStatus(0, 0.0, 0.0, 0.0),
29+
{ s, r ->
30+
AverageHealthStatus(
31+
s.cnt + 1,
32+
s.temperature + r.temperature,
33+
s.bloodPressure + r.bloodPressure,
34+
s.heartRate + r.heartRate,
35+
)
36+
},
37+
).map { s ->
38+
AverageHealthStatus(
39+
s.cnt,
40+
if (s.cnt != 0) s.temperature / s.cnt else 0.0,
41+
if (s.cnt != 0) s.bloodPressure / s.cnt else 0.0,
42+
if (s.cnt != 0) s.heartRate / s.cnt else 0.0,
43+
)
44+
}
45+
}

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import reactor.core.publisher.Mono
99

1010
@RestController
1111
class ProfileController(val repository: ProfileRepository) {
12-
1312
@PostMapping("/profile")
14-
fun save(@RequestBody profile: Profile): Mono<Profile> = repository.save(profile)
15-
}
13+
fun save(
14+
@RequestBody profile: Profile,
15+
): Mono<Profile> = repository.save(profile)
16+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
package com.baeldung.bootmicroservice.model;
1+
package com.baeldung.bootmicroservice.model
22

33
class AverageHealthStatus(var cnt: Int, var temperature: Double, var bloodPressure: Double, var heartRate: Double)

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ import org.springframework.data.relational.core.mapping.Table
55
import java.time.LocalDate
66

77
@Table
8-
data class HealthRecord(@Id var id: Long?, var profileId: Long?, var temperature: Double, var bloodPressure: Double, var heartRate: Double, var date: LocalDate)
8+
data class HealthRecord(
9+
@Id var id: Long?,
10+
var profileId: Long?,
11+
var temperature: Double,
12+
var bloodPressure: Double,
13+
var heartRate: Double,
14+
var date: LocalDate,
15+
)

spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ import org.springframework.data.relational.core.mapping.Table
55
import java.time.LocalDateTime
66

77
@Table
8-
data class Profile(@Id var id:Long?, var firstName : String, var lastName : String, var birthDate: LocalDateTime)
8+
data class Profile(
9+
@Id var id: Long?,
10+
var firstName: String,
11+
var lastName: String,
12+
var birthDate: LocalDateTime,
13+
)

0 commit comments

Comments
 (0)