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:
model
package: containing the domain model classes (e.g.,Book
,Author
)repository
package: containing the repository interfaces extendingJpaRepository
service
package: containing the service classes for business logiccontroller
package: containing the REST API controllersexception
package: containing custom exception classesdto
package: containing the data transfer objects used in the API
- Implement the domain model:
Book
class: should have fields forid
,title
,isbn
,publishDate
,price
, and anAuthor
relationship (ManyToOne)Author
class: should have fields forid
,name
,email
, and a list ofBook
relationships (OneToMany)
- Implement the repositories:
BookRepository
interface: should extendJpaRepository<Book, Long>
AuthorRepository
interface: should extendJpaRepository<Author, Long>
- Implement the services:
BookService
class: should contain methods for creating, updating, deleting, and retrieving booksAuthorService
class: should contain methods for creating, updating, deleting, and retrieving authors
- Implement the REST API controllers:
BookController
class: should handle HTTP requests for CRUD operations on booksAuthorController
class: 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 anAuthor
relationshipAuthorDTO
: should contain fields forid
,name
, andemail
- Implement exception handling:
- Create custom exceptions (e.g.,
ResourceNotFoundException
,BadRequestException
) - Implement a global exception handler using
@ControllerAdvice
to 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!