diff --git a/docker-example-service/pom.xml b/docker-example-service/pom.xml
index 428baa8..c5dc14b 100644
--- a/docker-example-service/pom.xml
+++ b/docker-example-service/pom.xml
@@ -7,7 +7,6 @@
4.0.0
- com.basaki.example
docker-example-service
jar
1.0
diff --git a/docker-example-service/src/main/java/com/basaki/example/docker/controller/BookController.java b/docker-example-service/src/main/java/com/basaki/example/docker/controller/BookController.java
index b418a87..731a226 100644
--- a/docker-example-service/src/main/java/com/basaki/example/docker/controller/BookController.java
+++ b/docker-example-service/src/main/java/com/basaki/example/docker/controller/BookController.java
@@ -8,16 +8,19 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+
import java.util.List;
import java.util.UUID;
+
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
+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.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@@ -34,7 +37,6 @@
@RestController
@Slf4j
@Api(value = "Book API",
- description = "Book API",
produces = "application/json", tags = {"API"})
public class BookController {
@@ -52,7 +54,7 @@ public class BookController {
@ApiResponses({
@ApiResponse(code = 201, response = Override.class,
message = "Override override created successfully")})
- @RequestMapping(method = RequestMethod.POST, value = BOOK_URL,
+ @PostMapping(value = BOOK_URL,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@@ -64,7 +66,7 @@ public Book create(@RequestBody BookRequest request) {
value = "Retrieves a book by ID.",
notes = "Requires a book identifier",
response = Book.class)
- @RequestMapping(method = RequestMethod.GET, value = BOOK_BY_ID_URL,
+ @GetMapping(value = BOOK_BY_ID_URL,
produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public Book getById(@PathVariable("id") UUID id) {
@@ -75,7 +77,7 @@ public Book getById(@PathVariable("id") UUID id) {
value = "Retrieves all books associated with a title, genre, publisher or combination of them.",
notes = "In absence of any parameter, it will return all authors",
response = Book.class, responseContainer = "List")
- @RequestMapping(method = RequestMethod.GET, value = BOOK_URL,
+ @GetMapping(value = BOOK_URL,
produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public List get(
@@ -86,14 +88,14 @@ public List get(
}
@ApiOperation(value = "Deletes a book by ID.")
- @RequestMapping(method = RequestMethod.DELETE, value = BOOK_BY_ID_URL)
+ @DeleteMapping(value = BOOK_BY_ID_URL)
@ResponseBody
public void deleteById(@PathVariable("id") UUID id) {
service.delete(id);
}
@ApiOperation(value = "Deletes all books.")
- @RequestMapping(method = RequestMethod.DELETE, value = BOOK_URL)
+ @DeleteMapping(value = BOOK_URL)
@ResponseBody
public void deleteAll() {
service.deleteAll();
diff --git a/docker-example-service/src/main/java/com/basaki/example/docker/controller/LandingController.java b/docker-example-service/src/main/java/com/basaki/example/docker/controller/LandingController.java
index 8290e23..4f64e10 100644
--- a/docker-example-service/src/main/java/com/basaki/example/docker/controller/LandingController.java
+++ b/docker-example-service/src/main/java/com/basaki/example/docker/controller/LandingController.java
@@ -2,7 +2,8 @@
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
-import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
@@ -17,7 +18,7 @@
@ApiIgnore
public class LandingController {
- @RequestMapping("/")
+ @GetMapping("/")
public void home(HttpServletResponse response) throws IOException {
response.sendRedirect("/swagger-ui.html");
}
diff --git a/docker-example-service/src/main/java/com/basaki/example/docker/service/BookService.java b/docker-example-service/src/main/java/com/basaki/example/docker/service/BookService.java
index e50ee15..4e3970c 100644
--- a/docker-example-service/src/main/java/com/basaki/example/docker/service/BookService.java
+++ b/docker-example-service/src/main/java/com/basaki/example/docker/service/BookService.java
@@ -4,6 +4,8 @@
import com.basaki.example.docker.model.Book;
import com.basaki.example.docker.model.BookRequest;
import com.basaki.example.docker.model.Genre;
+
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -64,34 +66,18 @@ public Book getById(UUID id) {
public List get(String title, Genre genre, String publisher) {
if (title == null && genre == null && publisher == null) {
- return bookMap.values().stream().collect(Collectors.toList());
+ return new ArrayList<>(bookMap.values());
}
- List books = bookMap.values().stream().filter(b -> {
- if (title != null && title.equalsIgnoreCase(b.getTitle())) {
- return true;
- } else {
- return true;
- }
- }).filter(b -> {
- if (genre != null && genre.equals(b.getGenre())) {
- return true;
- } else {
- return true;
- }
- }).filter(b -> {
- if (publisher != null && publisher.equalsIgnoreCase(
- b.getPublisher())) {
- return true;
- } else {
- return true;
- }
- }).collect(Collectors.toList());
-
- if (books == null || books.size() == 0) {
+ List books = bookMap.values().stream()
+ .filter(b -> title != null && title.equalsIgnoreCase(b.getTitle()))
+ .filter(b -> genre != null && genre.equals(b.getGenre()))
+ .filter(b -> publisher != null && publisher.equalsIgnoreCase(b.getPublisher()))
+ .collect(Collectors.toList());
+
+ if (books.isEmpty()) {
throw new InvalidSearchException("No books found!");
}
-
return books;
}
diff --git a/docker-example-service/src/main/java/com/basaki/example/docker/util/UuidBeanFactory.java b/docker-example-service/src/main/java/com/basaki/example/docker/util/UuidBeanFactory.java
index 6d440d9..316548b 100644
--- a/docker-example-service/src/main/java/com/basaki/example/docker/util/UuidBeanFactory.java
+++ b/docker-example-service/src/main/java/com/basaki/example/docker/util/UuidBeanFactory.java
@@ -19,8 +19,7 @@ public Object createBean(Object source, Class> sourceClass,
}
UUID uuidSrc = (UUID) source;
- UUID uuidDest = new UUID(uuidSrc.getMostSignificantBits(),
+ return new UUID(uuidSrc.getMostSignificantBits(),
uuidSrc.getLeastSignificantBits());
- return uuidDest;
}
}