@@ -11,41 +11,41 @@ import io.ktor.server.routing.*
11
11
fun Application.configureRouting () {
12
12
routing {
13
13
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
+ }
47
48
}
48
- }
49
49
}
50
50
}
51
51
}
0 commit comments