diff --git a/src/main/java/expert/os/demos/books/application/MovieMapper.java b/src/main/java/expert/os/demos/books/application/BookMapper.java similarity index 93% rename from src/main/java/expert/os/demos/books/application/MovieMapper.java rename to src/main/java/expert/os/demos/books/application/BookMapper.java index 0acf0f0..29739ea 100644 --- a/src/main/java/expert/os/demos/books/application/MovieMapper.java +++ b/src/main/java/expert/os/demos/books/application/BookMapper.java @@ -7,7 +7,7 @@ import org.mapstruct.Mapping; @Mapper(componentModel = "cdi") -public interface MovieMapper { +public interface BookMapper { BookResponse toResponse(Book book); diff --git a/src/main/java/expert/os/demos/books/application/BookService.java b/src/main/java/expert/os/demos/books/application/BookService.java index aa46881..1ff02ff 100644 --- a/src/main/java/expert/os/demos/books/application/BookService.java +++ b/src/main/java/expert/os/demos/books/application/BookService.java @@ -27,64 +27,64 @@ public class BookService { public static final Order ORDER = Order.by(Sort.asc("title")); private final BookRepository bookRepository; - private final MovieMapper movieMapper; + private final BookMapper bookMapper; @Inject - public BookService(@Database(DatabaseType.DOCUMENT) BookRepository bookRepository, MovieMapper movieMapper) { + public BookService(@Database(DatabaseType.DOCUMENT) BookRepository bookRepository, BookMapper bookMapper) { this.bookRepository = bookRepository; - this.movieMapper = movieMapper; + this.bookMapper = bookMapper; } public BookService() { this(null, null); } - public List getAllMovies(int page, int size) { - LOGGER.log(Level.INFO, "Fetching all movies with page: {0} and size: {1}", new Object[]{page, size}); + public List getAllBooks(int page, int size) { + LOGGER.log(Level.INFO, "Fetching all books with page: {0} and size: {1}", new Object[]{page, size}); PageRequest pageable = PageRequest.ofPage(page).size(size); - Page moviePage = bookRepository.findAll(pageable, ORDER); - List movies = moviePage.stream() - .map(movieMapper::toResponse) + Page bookPage = bookRepository.findAll(pageable, ORDER); + List books = bookPage.stream() + .map(bookMapper::toResponse) .collect(Collectors.toList()); - LOGGER.log(Level.INFO, "Retrieved {0} movies", movies.size()); - return movies; + LOGGER.log(Level.INFO, "Retrieved {0} books", books.size()); + return books; } public Optional findById(String id) { - LOGGER.log(Level.INFO, "Fetching movie with ID: {0}", id); - Optional movieResponse = bookRepository.findById(id) - .map(movieMapper::toResponse); - if (movieResponse.isPresent()) { - LOGGER.log(Level.INFO, "Movie found with ID: {0}", id); + LOGGER.log(Level.INFO, "Fetching book with ID: {0}", id); + Optional bookResponse = bookRepository.findById(id) + .map(bookMapper::toResponse); + if (bookResponse.isPresent()) { + LOGGER.log(Level.INFO, "Book found with ID: {0}", id); } else { - LOGGER.log(Level.WARNING, "Movie not found with ID: {0}", id); + LOGGER.log(Level.WARNING, "Book not found with ID: {0}", id); } - return movieResponse; + return bookResponse; } public BookResponse create(BookRequest bookRequest) { - LOGGER.log(Level.INFO, "Creating new movie with title: {0}", bookRequest.getTitle()); - Book book = movieMapper.toEntity(bookRequest, UUID.randomUUID().toString()); + LOGGER.log(Level.INFO, "Creating new book with title: {0}", bookRequest.getTitle()); + Book book = bookMapper.toEntity(bookRequest, UUID.randomUUID().toString()); Book savedBook = bookRepository.save(book); - LOGGER.log(Level.INFO, "Movie created with ID: {0}", savedBook.getId()); - return movieMapper.toResponse(savedBook); + LOGGER.log(Level.INFO, "Book created with ID: {0}", savedBook.getId()); + return bookMapper.toResponse(savedBook); } public Optional update(String id, BookRequest bookRequest) { - LOGGER.log(Level.INFO, "Updating movie with ID: {0}", id); + LOGGER.log(Level.INFO, "Updating book with ID: {0}", id); return bookRepository.findById(id) - .map(existingMovie -> { - Book updatedBook = movieMapper.toEntity(bookRequest); - existingMovie.update(updatedBook); + .map(existingBook -> { + Book updatedBook = bookMapper.toEntity(bookRequest); + existingBook.update(updatedBook); Book savedBook = bookRepository.save(updatedBook); - LOGGER.log(Level.INFO, "Movie updated with ID: {0}", id); - return movieMapper.toResponse(savedBook); + LOGGER.log(Level.INFO, "Book updated with ID: {0}", id); + return bookMapper.toResponse(savedBook); }); } public void delete(String id) { - LOGGER.log(Level.INFO, "Deleting movie with ID: {0}", id); + LOGGER.log(Level.INFO, "Deleting book with ID: {0}", id); bookRepository.deleteById(id); } } diff --git a/src/test/java/expert/os/demos/books/application/BookMapperTest.java b/src/test/java/expert/os/demos/books/application/BookMapperTest.java index 3f6ffa2..9cfd91b 100644 --- a/src/test/java/expert/os/demos/books/application/BookMapperTest.java +++ b/src/test/java/expert/os/demos/books/application/BookMapperTest.java @@ -16,11 +16,11 @@ class BookMapperTest { - private MovieMapper movieMapper; + private BookMapper bookMapper; @BeforeEach void setUp() { - movieMapper = Mappers.getMapper(MovieMapper.class); + bookMapper = Mappers.getMapper(BookMapper.class); } @@ -36,7 +36,7 @@ void shouldMapMovieToMovieResponse() { .set(field("tags"), Arrays.asList("Leonardo DiCaprio", "Joseph Gordon-Levitt")) .create(); - var movieResponse = movieMapper.toResponse(movie); + var movieResponse = bookMapper.toResponse(movie); SoftAssertions.assertSoftly(soft -> { soft.assertThat(movieResponse).isNotNull(); @@ -59,7 +59,7 @@ void shouldMapMovieRequestToMovieWithNewUUID() { movieRequest.setAuthor("Christopher Nolan"); movieRequest.setTags(Arrays.asList("Leonardo DiCaprio", "Joseph Gordon-Levitt")); - var movie = movieMapper.toEntity(movieRequest); + var movie = bookMapper.toEntity(movieRequest); SoftAssertions.assertSoftly(soft -> { soft.assertThat(movie).isNotNull();