Skip to content

Commit 193d218

Browse files
authored
Merge pull request #181 from nanotaboada/feature/naming-conventions
refactor: adjust naming and formatting to follow conventions
2 parents 0a56c7b + 40ade70 commit 193d218

File tree

12 files changed

+619
-553
lines changed

12 files changed

+619
-553
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"editor.rulers": [80],
3+
"editor.tabSize": 4,
4+
"editor.insertSpaces": true,
5+
"editor.detectIndentation": false,
6+
"editor.formatOnSave": true,
7+
"[java]": {
8+
"editor.defaultFormatter": "redhat.java"
9+
},
310
"java.configuration.updateBuildConfiguration": "automatic",
411
"java.compile.nullAnalysis.mode": "automatic",
512
"sonarlint.connectedMode.project": {

assets/images/structure.svg

Lines changed: 1 addition & 1 deletion
Loading

assets/images/swagger.png

8.23 KB
Loading

src/main/java/ar/com/nanotaboada/java/samples/spring/boot/Application.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import ar.com.nanotaboada.java.samples.spring.boot.repositories.BooksRepository;
1515

1616
/**
17-
* A configuration class that declares one or more Bean methods and also triggers auto-configuration
18-
* and component scanning.
19-
* */
17+
* A configuration class that declares one or more Bean methods and also
18+
* triggers auto-configuration and component scanning.
19+
*/
2020
@SpringBootApplication
2121
@EnableCaching
2222
public class Application {

src/main/java/ar/com/nanotaboada/java/samples/spring/boot/controllers/BooksController.java

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,37 @@
3030

3131
@RestController
3232
@Tag(name = "Books")
33-
@OpenAPIDefinition(
34-
info = @Info(
35-
title = "java.samples.spring.boot",
36-
version = "1.0",
37-
description = "🧪 Proof of Concept for a RESTful Web Service made with JDK 21 (LTS) and Spring Boot 3",
38-
contact = @Contact(
39-
name = "GitHub",
40-
url = "https://github.com/nanotaboada/java.samples.spring.boot"
41-
),
42-
license = @License(
43-
name = "MIT License",
44-
url = "https://opensource.org/licenses/MIT"
45-
)
46-
)
47-
)
33+
@OpenAPIDefinition(info = @Info(title = "java.samples.spring.boot", version = "1.0", description = "🧪 Proof of Concept for a RESTful Web Service made with JDK 21 (LTS) and Spring Boot 3", contact = @Contact(name = "GitHub", url = "https://github.com/nanotaboada/java.samples.spring.boot"), license = @License(name = "MIT License", url = "https://opensource.org/licenses/MIT")))
4834
public class BooksController {
4935

50-
private final BooksService service;
36+
private final BooksService booksService;
5137

52-
public BooksController(BooksService service) {
53-
this.service = service;
38+
public BooksController(BooksService booksService) {
39+
this.booksService = booksService;
5440
}
5541

56-
/* --------------------------------------------------------------------------------------------
42+
/*
43+
* -------------------------------------------------------------------------
5744
* HTTP POST
58-
* ----------------------------------------------------------------------------------------- */
45+
* -------------------------------------------------------------------------
46+
*/
5947

6048
@PostMapping("/books")
6149
@Operation(summary = "Creates a new book")
6250
@ApiResponses(value = {
63-
@ApiResponse(responseCode = "201", description = "Created", content = @Content),
64-
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
65-
@ApiResponse(responseCode = "409", description = "Conflict", content = @Content)
51+
@ApiResponse(responseCode = "201", description = "Created", content = @Content),
52+
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
53+
@ApiResponse(responseCode = "409", description = "Conflict", content = @Content)
6654
})
6755
public ResponseEntity<String> post(@RequestBody BookDTO bookDTO) {
68-
if (service.retrieveByIsbn(bookDTO.getIsbn()) != null) {
56+
if (booksService.retrieveByIsbn(bookDTO.getIsbn()) != null) {
6957
return new ResponseEntity<>(HttpStatus.CONFLICT);
7058
} else {
71-
if (service.create(bookDTO)) {
59+
if (booksService.create(bookDTO)) {
7260
URI location = MvcUriComponentsBuilder
73-
.fromMethodName(BooksController.class, "getByIsbn", bookDTO.getIsbn())
74-
.build()
75-
.toUri();
61+
.fromMethodName(BooksController.class, "getByIsbn", bookDTO.getIsbn())
62+
.build()
63+
.toUri();
7664
HttpHeaders httpHeaders = new HttpHeaders();
7765
httpHeaders.setLocation(location);
7866
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
@@ -82,19 +70,20 @@ public ResponseEntity<String> post(@RequestBody BookDTO bookDTO) {
8270
}
8371
}
8472

85-
/* --------------------------------------------------------------------------------------------
73+
/*
74+
* -------------------------------------------------------------------------
8675
* HTTP GET
87-
* ----------------------------------------------------------------------------------------- */
76+
* -------------------------------------------------------------------------
77+
*/
8878

8979
@GetMapping("/books/{isbn}")
9080
@Operation(summary = "Retrieves a book by its ID")
9181
@ApiResponses(value = {
92-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema =
93-
@Schema(implementation = BookDTO.class))),
94-
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
82+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = BookDTO.class))),
83+
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
9584
})
9685
public ResponseEntity<BookDTO> getByIsbn(@PathVariable String isbn) {
97-
BookDTO bookDTO = service.retrieveByIsbn(isbn);
86+
BookDTO bookDTO = booksService.retrieveByIsbn(isbn);
9887
if (bookDTO != null) {
9988
return new ResponseEntity<>(bookDTO, HttpStatus.OK);
10089
} else {
@@ -105,28 +94,29 @@ public ResponseEntity<BookDTO> getByIsbn(@PathVariable String isbn) {
10594
@GetMapping("/books")
10695
@Operation(summary = "Retrieves all books")
10796
@ApiResponses(value = {
108-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema =
109-
@Schema(implementation = BookDTO[].class)))
97+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = BookDTO[].class)))
11098
})
11199
public ResponseEntity<List<BookDTO>> getAll() {
112-
List<BookDTO> books = service.retrieveAll();
100+
List<BookDTO> books = booksService.retrieveAll();
113101
return new ResponseEntity<>(books, HttpStatus.OK);
114102
}
115103

116-
/* --------------------------------------------------------------------------------------------
104+
/*
105+
* -------------------------------------------------------------------------
117106
* HTTP PUT
118-
* ----------------------------------------------------------------------------------------- */
107+
* -------------------------------------------------------------------------
108+
*/
119109

120110
@PutMapping("/books")
121111
@Operation(summary = "Updates (entirely) a book by its ID")
122112
@ApiResponses(value = {
123-
@ApiResponse(responseCode = "204", description = "No Content", content = @Content),
124-
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
125-
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
113+
@ApiResponse(responseCode = "204", description = "No Content", content = @Content),
114+
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
115+
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
126116
})
127117
public ResponseEntity<String> put(@RequestBody BookDTO bookDTO) {
128-
if (service.retrieveByIsbn(bookDTO.getIsbn()) != null) {
129-
if (service.update(bookDTO)) {
118+
if (booksService.retrieveByIsbn(bookDTO.getIsbn()) != null) {
119+
if (booksService.update(bookDTO)) {
130120
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
131121
} else {
132122
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
@@ -136,20 +126,22 @@ public ResponseEntity<String> put(@RequestBody BookDTO bookDTO) {
136126
}
137127
}
138128

139-
/* --------------------------------------------------------------------------------------------
129+
/*
130+
* -------------------------------------------------------------------------
140131
* HTTP DELETE
141-
* ----------------------------------------------------------------------------------------- */
132+
* -------------------------------------------------------------------------
133+
*/
142134

143135
@DeleteMapping("/books/{isbn}")
144136
@Operation(summary = "Deletes a book by its ID")
145137
@ApiResponses(value = {
146-
@ApiResponse(responseCode = "204", description = "No Content", content = @Content),
147-
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
148-
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
138+
@ApiResponse(responseCode = "204", description = "No Content", content = @Content),
139+
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
140+
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content)
149141
})
150142
public ResponseEntity<String> delete(@PathVariable String isbn) {
151-
if (service.retrieveByIsbn(isbn) != null) {
152-
if (service.delete(isbn)) {
143+
if (booksService.retrieveByIsbn(isbn) != null) {
144+
if (booksService.delete(isbn)) {
153145
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
154146
} else {
155147
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);

0 commit comments

Comments
 (0)