-
Notifications
You must be signed in to change notification settings - Fork 1
/
CarController.java
51 lines (42 loc) · 1.3 KB
/
CarController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.demo.car;
import java.util.Arrays;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@RestController
@RequestMapping("/cars")
@Api(value="Car Controller")
public class CarController {
@ApiOperation(value = "Get the list of cars")
@GetMapping
public List<Car> getCars() {
return Arrays.asList(new Car[]{
new Car(1, "Ford", 2011, "Black"),
new Car(2, "Honda", 2012, "Red"),
new Car(3, "Chevrolet", 2013, "Green"),
new Car(4, "Nissan", 2014, "Blue"),
new Car(5, "Toyota", 2015, "Yellow"),
});
}
@ApiOperation(value = "Repair the car", consumes = "application/json")
@PostMapping("/repair")
public String repairCar(
@ApiParam(
required = true,
value="When and where the service should be provided."
)
@RequestBody ServiceRequest request
) {
return String.format(
"Your car will be repaired on '%s' at '%s'.",
request.getWhen(),
request.getWhere()
);
}
}