5
5
import com .kaluzny .demo .exception .AutoWasDeletedException ;
6
6
import com .kaluzny .demo .exception .ThereIsNoSuchAutoException ;
7
7
import io .swagger .v3 .oas .annotations .Hidden ;
8
- import io .swagger .v3 .oas .annotations .Operation ;
9
8
import io .swagger .v3 .oas .annotations .Parameter ;
10
- import io .swagger .v3 .oas .annotations .media .ArraySchema ;
11
- import io .swagger .v3 .oas .annotations .media .Content ;
12
- import io .swagger .v3 .oas .annotations .media .Schema ;
13
- import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
14
- import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
15
- import io .swagger .v3 .oas .annotations .tags .Tag ;
16
9
import jakarta .annotation .PostConstruct ;
17
- import jakarta .annotation .security .RolesAllowed ;
18
- import jakarta .validation .constraints .NotNull ;
10
+ import jakarta .validation .Valid ;
19
11
import lombok .RequiredArgsConstructor ;
20
12
import lombok .extern .slf4j .Slf4j ;
21
13
import org .springframework .cache .annotation .CacheEvict ;
22
- import org .springframework .cache .annotation .Cacheable ;
23
14
import org .springframework .data .domain .PageRequest ;
24
15
import org .springframework .data .domain .Sort ;
25
16
import org .springframework .http .HttpStatus ;
38
29
@ RequestMapping (value = "/api" , produces = MediaType .APPLICATION_JSON_VALUE )
39
30
@ RequiredArgsConstructor
40
31
@ Slf4j
41
- @ Tag (name = "Automobile" , description = "the Automobile API" )
42
- public class AutomobileRestController {
32
+ public class AutomobileRestController implements AutomobileResource , AutomobileOpenApi {
43
33
44
34
private final AutomobileRepository repository ;
45
35
@@ -53,27 +43,17 @@ public void init() {
53
43
repository .save (new Automobile (1L , "Ford" , "Green" , Instant .now (), Instant .now (), true , false ));
54
44
}
55
45
56
- /*@Operation(summary = "Add a new Automobile", description = "endpoint for creating an entity", tags = {"Automobile"})
57
- @ApiResponses(value = {
58
- @ApiResponse(responseCode = "201", description = "Automobile created"),
59
- @ApiResponse(responseCode = "400", description = "Invalid input"),
60
- @ApiResponse(responseCode = "409", description = "Automobile already exists")})*/
61
46
@ PostMapping ("/automobiles" )
62
47
@ ResponseStatus (HttpStatus .CREATED )
63
48
@ PreAuthorize ("hasRole('ADMIN')" )
64
49
//@RolesAllowed("ADMIN")
65
- public Automobile saveAutomobile (
66
- @ Parameter (description = "Automobile" , required = true ) @ NotNull @ RequestBody Automobile automobile ) {
50
+ public Automobile saveAutomobile (@ Valid @ RequestBody Automobile automobile ) {
67
51
log .info ("saveAutomobile() - start: automobile = {}" , automobile );
68
52
Automobile savedAutomobile = repository .save (automobile );
69
53
log .info ("saveAutomobile() - end: savedAutomobile = {}" , savedAutomobile .getId ());
70
54
return savedAutomobile ;
71
55
}
72
56
73
- @ Operation (summary = "Find all Automobiles" , description = " " , tags = {"Automobile" })
74
- @ ApiResponses (value = {
75
- @ ApiResponse (responseCode = "200" , description = "successful operation" ,
76
- content = @ Content (array = @ ArraySchema (schema = @ Schema (implementation = Automobile .class ))))})
77
57
@ GetMapping ("/automobiles" )
78
58
@ ResponseStatus (HttpStatus .OK )
79
59
//@Cacheable(value = "automobile", sync = true)
@@ -85,17 +65,10 @@ public Collection<Automobile> getAllAutomobiles() {
85
65
return collection ;
86
66
}
87
67
88
- @ Operation (summary = "Find automobile by ID" , description = "Returns a single automobile" , tags = {"Automobile" })
89
- @ ApiResponses (value = {
90
- @ ApiResponse (responseCode = "200" , description = "successful operation" ,
91
- content = @ Content (schema = @ Schema (implementation = Automobile .class ))),
92
- @ ApiResponse (responseCode = "404" , description = "There is no such automobile" )})
93
68
@ GetMapping ("/automobiles/{id}" )
94
69
@ ResponseStatus (HttpStatus .OK )
95
70
//@Cacheable(value = "automobile", sync = true)
96
- public Automobile getAutomobileById (
97
- @ Parameter (description = "Id of the Automobile to be obtained. Cannot be empty." , required = true )
98
- @ PathVariable Long id ) {
71
+ public Automobile getAutomobileById (@ PathVariable Long id ) {
99
72
log .info ("getAutomobileById() - start: id = {}" , id );
100
73
Automobile receivedAutomobile = repository .findById (id )
101
74
//.orElseThrow(() -> new EntityNotFoundException("Automobile not found with id = " + id));
@@ -108,35 +81,19 @@ public Automobile getAutomobileById(
108
81
}
109
82
110
83
@ Hidden
111
- @ Operation (summary = "Find automobile by name" , description = " " , tags = {"Automobile" })
112
- @ ApiResponses (value = {
113
- @ ApiResponse (responseCode = "200" , description = "successful operation" ,
114
- content = @ Content (array = @ ArraySchema (schema = @ Schema (implementation = Automobile .class ))))})
115
84
@ GetMapping (value = "/automobiles" , params = {"name" })
116
85
@ ResponseStatus (HttpStatus .OK )
117
- public Collection <Automobile > findAutomobileByName (
118
- @ Parameter (description = "Name of the Automobile to be obtained. Cannot be empty." , required = true )
119
- @ RequestParam (value = "name" ) String name ) {
86
+ public Collection <Automobile > findAutomobileByName (@ RequestParam (value = "name" ) String name ) {
120
87
log .info ("findAutomobileByName() - start: name = {}" , name );
121
88
Collection <Automobile > collection = repository .findByName (name );
122
89
log .info ("findAutomobileByName() - end: collection = {}" , collection );
123
90
return collection ;
124
91
}
125
92
126
- @ Operation (summary = "Update an existing Automobile" , description = "need to fill" , tags = {"Automobile" })
127
- @ ApiResponses (value = {
128
- @ ApiResponse (responseCode = "200" , description = "successful operation" ),
129
- @ ApiResponse (responseCode = "400" , description = "Invalid ID supplied" ),
130
- @ ApiResponse (responseCode = "404" , description = "Automobile not found" ),
131
- @ ApiResponse (responseCode = "405" , description = "Validation exception" )})
132
93
@ PutMapping ("/automobiles/{id}" )
133
94
@ ResponseStatus (HttpStatus .OK )
134
95
//@CachePut(value = "automobile", key = "#id")
135
- public Automobile refreshAutomobile (
136
- @ Parameter (description = "Id of the Automobile to be update. Cannot be empty." , required = true )
137
- @ PathVariable Long id ,
138
- @ Parameter (description = "Automobile to update." , required = true )
139
- @ RequestBody Automobile automobile ) {
96
+ public Automobile refreshAutomobile (@ PathVariable Long id , @ RequestBody Automobile automobile ) {
140
97
log .info ("refreshAutomobile() - start: id = {}, automobile = {}" , id , automobile );
141
98
Automobile updatedAutomobile = repository .findById (id )
142
99
.map (entity -> {
@@ -155,16 +112,10 @@ public Automobile refreshAutomobile(
155
112
return updatedAutomobile ;
156
113
}
157
114
158
- @ Operation (summary = "Deletes a Automobile" , description = "need to fill" , tags = {"Automobile" })
159
- @ ApiResponses (value = {
160
- @ ApiResponse (responseCode = "200" , description = "successful operation" ),
161
- @ ApiResponse (responseCode = "404" , description = "Automobile not found" )})
162
115
@ DeleteMapping ("/automobiles/{id}" )
163
116
@ ResponseStatus (HttpStatus .NO_CONTENT )
164
117
@ CacheEvict (value = "automobile" , key = "#id" )
165
- public String removeAutomobileById (
166
- @ Parameter (description = "Id of the Automobile to be delete. Cannot be empty." , required = true )
167
- @ PathVariable Long id ) {
118
+ public String removeAutomobileById (@ PathVariable Long id ) {
168
119
log .info ("removeAutomobileById() - start: id = {}" , id );
169
120
Automobile deletedAutomobile = repository .findById (id )
170
121
.orElseThrow (ThereIsNoSuchAutoException ::new );
0 commit comments