Project: Online Book Store API
Objective: Implement a RESTful API for an online book store using Java and Spring Boot. The API should allow users to perform CRUD (Create, Read, Update, Delete) operations on books and authors.
Requirements:
- Create a new Spring Boot project using Spring Initializr. Include the following dependencies: Web, JPA, and H2.
- Set up the project with the following structure:
modelpackage: containing the domain model classes (e.g.,Book,Author)repositorypackage: containing the repository interfaces extendingJpaRepositoryservicepackage: containing the service classes for business logiccontrollerpackage: containing the REST API controllersexceptionpackage: containing custom exception classesdtopackage: containing the data transfer objects used in the API
- Implement the domain model:
Bookclass: should have fields forid,title,isbn,publishDate,price, and anAuthorrelationship (ManyToOne)Authorclass: should have fields forid,name,email, and a list ofBookrelationships (OneToMany)
- Implement the repositories:
BookRepositoryinterface: should extendJpaRepository<Book, Long>AuthorRepositoryinterface: should extendJpaRepository<Author, Long>
- Implement the services:
BookServiceclass: should contain methods for creating, updating, deleting, and retrieving booksAuthorServiceclass: should contain methods for creating, updating, deleting, and retrieving authors
- Implement the REST API controllers:
BookControllerclass: should handle HTTP requests for CRUD operations on booksAuthorControllerclass: should handle HTTP requests for CRUD operations on authors
- Implement the data transfer objects (DTOs) for the API:
BookDTO: should contain fields forid,title,isbn,publishDate,price, and anAuthorrelationshipAuthorDTO: should contain fields forid,name, andemail
- Implement exception handling:
- Create custom exceptions (e.g.,
ResourceNotFoundException,BadRequestException) - Implement a global exception handler using
@ControllerAdviceto handle exceptions and return appropriate HTTP response status codes
- Create custom exceptions (e.g.,
- Configure an H2 in-memory database for the application.
- Write unit tests for the service classes using JUnit and Mockito.
- (Optional) Implement API documentation using Swagger or OpenAPI.
Deliverables:
- A fully functional Spring Boot project, including source code and tests
- A README file explaining how to build and run the project, as well as any design decisions made
When submitting your project, make sure to include all the necessary files in a single archive (e.g., ZIP or TAR) and provide clear instructions for building and running your application. Good luck!