Skip to content

Commit 5d2cc18

Browse files
committed
fix formatting
1 parent c4e1df2 commit 5d2cc18

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

kotlin-ktor/src/main/java/com/baeldung/testing/plugins/ConfigureRouting.kt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@ import io.ktor.server.routing.*
1111
fun Application.configureRouting() {
1212
routing {
1313
route("cars") {
14-
get {
15-
call.respond(CarStorageMock.carStorage)
16-
}
17-
get("{id?}") {
18-
val id = call.parameters["id"]
19-
val car = CarStorageMock.carStorage.find { it.id == id } ?: return@get call.respondText(
20-
text = "car.not.found",
21-
status = HttpStatusCode.NotFound
22-
)
23-
call.respond(car)
24-
}
25-
post {
26-
val car = call.receive<Car>()
27-
CarStorageMock.carStorage.add(car)
28-
call.respond(status = HttpStatusCode.Created, message = car)
29-
}
30-
put("{id?}") {
31-
val id = call.parameters["id"]
32-
val car = CarStorageMock.carStorage.find { it.id == id } ?: return@put call.respondText(
33-
text = "car.not.found",
34-
status = HttpStatusCode.NotFound
35-
)
36-
val carUpdate = call.receive<Car>()
37-
car.brand = carUpdate.brand
38-
car.price = carUpdate.price
39-
call.respond(car)
40-
}
41-
delete("{id?}") {
42-
val id = call.parameters["id"]
43-
if (CarStorageMock.carStorage.removeIf { it.id == id }) {
44-
call.respondText(text = "car.deleted", status = HttpStatusCode.OK)
45-
} else {
46-
call.respondText(text = "car.not.found", status = HttpStatusCode.NotFound)
14+
get {
15+
call.respond(CarStorageMock.carStorage)
16+
}
17+
get("{id?}") {
18+
val id = call.parameters["id"]
19+
val car = CarStorageMock.carStorage.find { it.id == id } ?: return@get call.respondText(
20+
text = "car.not.found",
21+
status = HttpStatusCode.NotFound
22+
)
23+
call.respond(car)
24+
}
25+
post {
26+
val car = call.receive<Car>()
27+
CarStorageMock.carStorage.add(car)
28+
call.respond(status = HttpStatusCode.Created, message = car)
29+
}
30+
put("{id?}") {
31+
val id = call.parameters["id"]
32+
val car = CarStorageMock.carStorage.find { it.id == id } ?: return@put call.respondText(
33+
text = "car.not.found",
34+
status = HttpStatusCode.NotFound
35+
)
36+
val carUpdate = call.receive<Car>()
37+
car.brand = carUpdate.brand
38+
car.price = carUpdate.price
39+
call.respond(car)
40+
}
41+
delete("{id?}") {
42+
val id = call.parameters["id"]
43+
if (CarStorageMock.carStorage.removeIf { it.id == id }) {
44+
call.respondText(text = "car.deleted", status = HttpStatusCode.OK)
45+
} else {
46+
call.respondText(text = "car.not.found", status = HttpStatusCode.NotFound)
47+
}
4748
}
48-
}
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)