Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-example-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.basaki.example</groupId>
<artifactId>docker-example-service</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +37,6 @@
@RestController
@Slf4j
@Api(value = "Book API",
description = "Book API",
produces = "application/json", tags = {"API"})
public class BookController {

Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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<Book> get(
Expand All @@ -86,14 +88,14 @@ public List<Book> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,7 +18,7 @@
@ApiIgnore
public class LandingController {

@RequestMapping("/")
@GetMapping("/")
public void home(HttpServletResponse response) throws IOException {
response.sendRedirect("/swagger-ui.html");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,34 +66,18 @@ public Book getById(UUID id) {
public List<Book> 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<Book> 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<Book> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}