diff --git a/src/main/java/expert/os/demos/books/api/MovieResource.java b/src/main/java/expert/os/demos/books/api/BookResource.java similarity index 87% rename from src/main/java/expert/os/demos/books/api/MovieResource.java rename to src/main/java/expert/os/demos/books/api/BookResource.java index 47964cd..d0fc906 100644 --- a/src/main/java/expert/os/demos/books/api/MovieResource.java +++ b/src/main/java/expert/os/demos/books/api/BookResource.java @@ -1,7 +1,7 @@ package expert.os.demos.books.api; -import expert.os.demos.books.application.MovieService; +import expert.os.demos.books.application.BookService; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.*; @@ -23,17 +23,17 @@ @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Tag(name = "Movies", description = "Operations related to movies") -public class MovieResource { +public class BookResource { - private final MovieService movieService; + private final BookService bookService; @Inject - public MovieResource(MovieService movieService) { - this.movieService = movieService; + public BookResource(BookService bookService) { + this.bookService = bookService; } - public MovieResource() { + public BookResource() { this(null); } @@ -46,7 +46,7 @@ public Response getAllMovies( @QueryParam("page") @DefaultValue("1") int page, @Parameter(description = "Number of items per page", example = "10") @QueryParam("size") @DefaultValue("10") int size) { - List movies = movieService.getAllMovies(page, size); + List movies = bookService.getAllMovies(page, size); return Response.ok(movies).build(); } @@ -59,7 +59,7 @@ public Response getAllMovies( public Response getMovieById( @Parameter(description = "ID of the movie to retrieve", required = true) @PathParam("id") String id) { - Optional movieResponse = movieService.getMovieById(id); + Optional movieResponse = bookService.findById(id); return movieResponse.map(Response::ok) .orElse(Response.status(Response.Status.NOT_FOUND)) .build(); @@ -72,7 +72,7 @@ public Response getMovieById( public Response createMovie( @Parameter(description = "Movie data to be created", required = true) BookRequest bookRequest) { - BookResponse bookResponse = movieService.createMovie(bookRequest); + BookResponse bookResponse = bookService.create(bookRequest); return Response.status(Response.Status.CREATED).entity(bookResponse).build(); } @@ -86,7 +86,7 @@ public Response updateMovie( @PathParam("id") String id, @Parameter(description = "Updated movie data", required = true) BookRequest bookRequest) { - Optional updatedMovie = movieService.updateMovie(id, bookRequest); + Optional updatedMovie = bookService.update(id, bookRequest); return updatedMovie.map(Response::ok) .orElse(Response.status(Response.Status.NOT_FOUND)) .build(); @@ -100,7 +100,7 @@ public Response updateMovie( public Response deleteMovie( @Parameter(description = "ID of the movie to delete", required = true) @PathParam("id") String id) { - movieService.deleteMovie(id); + bookService.delete(id); return Response.noContent().build(); } } diff --git a/src/main/java/expert/os/demos/books/application/MovieService.java b/src/main/java/expert/os/demos/books/application/BookService.java similarity index 85% rename from src/main/java/expert/os/demos/books/application/MovieService.java rename to src/main/java/expert/os/demos/books/application/BookService.java index 4ec0b49..aa46881 100644 --- a/src/main/java/expert/os/demos/books/application/MovieService.java +++ b/src/main/java/expert/os/demos/books/application/BookService.java @@ -21,21 +21,21 @@ import java.util.stream.Collectors; @ApplicationScoped -public class MovieService { +public class BookService { - private static final Logger LOGGER = Logger.getLogger(MovieService.class.getName()); + private static final Logger LOGGER = Logger.getLogger(BookService.class.getName()); public static final Order ORDER = Order.by(Sort.asc("title")); private final BookRepository bookRepository; private final MovieMapper movieMapper; @Inject - public MovieService(@Database(DatabaseType.DOCUMENT) BookRepository bookRepository, MovieMapper movieMapper) { + public BookService(@Database(DatabaseType.DOCUMENT) BookRepository bookRepository, MovieMapper movieMapper) { this.bookRepository = bookRepository; this.movieMapper = movieMapper; } - public MovieService() { + public BookService() { this(null, null); } @@ -51,7 +51,7 @@ public List getAllMovies(int page, int size) { return movies; } - public Optional getMovieById(String id) { + public Optional findById(String id) { LOGGER.log(Level.INFO, "Fetching movie with ID: {0}", id); Optional movieResponse = bookRepository.findById(id) .map(movieMapper::toResponse); @@ -63,7 +63,7 @@ public Optional getMovieById(String id) { return movieResponse; } - public BookResponse createMovie(BookRequest bookRequest) { + 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()); Book savedBook = bookRepository.save(book); @@ -71,7 +71,7 @@ public BookResponse createMovie(BookRequest bookRequest) { return movieMapper.toResponse(savedBook); } - public Optional updateMovie(String id, BookRequest bookRequest) { + public Optional update(String id, BookRequest bookRequest) { LOGGER.log(Level.INFO, "Updating movie with ID: {0}", id); return bookRepository.findById(id) .map(existingMovie -> { @@ -83,7 +83,7 @@ public Optional updateMovie(String id, BookRequest bookRequest) { }); } - public void deleteMovie(String id) { + public void delete(String id) { LOGGER.log(Level.INFO, "Deleting movie with ID: {0}", id); bookRepository.deleteById(id); }