This project is a simple Spring Boot application that provides a RESTful API for managing books. It allows users to perform CRUD (Create, Read, Update, Delete) operations on books using the API. It adding new books, updating existing ones, searching for books, and deleting books.
The project consists of several components, each serving a specific purpose:
-
Controller: Defines the RESTful endpoints for handling book-related requests. It interacts with the Service to perform various operations.
-
Service: Contains the business logic for book-related operations. It interacts with the DAO to access the database.
-
DAO: Provides access to the database using Spring Data JPA. It extends the JpaRepository interface to enable CRUD operations.
-
Entities: Represents the entity (model) for a book. It is annotated with
@Entity
to indicate it's a JPA entity and corresponds to a database table.
API Collection Documentation on Postman for testing API
Add a new book to the database.
- URL: POST
/addBook
- Request Body:
{ "bookName": "Book Title", "authorName": "Author Name", "bookPrice": 29.99, "stockQuantity": 50 }
- Response:
- 201 Created: Book added successfully
- 409 CONFLICT: if there is a conflict (e.g., book not able to store ).
- 500 INTERNAL_SERVER_ERROR: if there is an internal server error.
Update an existing book's details by providing the book ID.
- URL: PUT
/updatebook/{bookid}
- Request Body:
{ "bookName": "Updated Book Name", "authorName": "Updated Author Name", "bookPrice": "Updated Book Price", "stockQuantity": "Updated Stock Quantity" }
- Response:
- 202 Accepted: Book updated successfully
- 404 Not Found: Book with the given ID not found
Endpoint | Method | URL | Request Parameter | Response |
---|---|---|---|---|
Get All Books | GET | /getAllBooks | None | List of BookEntity objects |
Get Book by ID | GET | /getBookById/{id} | id (Path parameter) | BookEntity object |
Get Books by Name Starting With | GET | /bookNameStartWith/{bookName} | bookName (Path parameter) | List of BookEntity objects |
Get Books by Name Ending With | GET | /bookNameEndWith/{bookName} | bookName (Path parameter) | List of BookEntity objects |
Get Books by Name Containing | GET | /bookNameContain/{bookName} | bookName (Path parameter) | List of BookEntity objects |
Endpoint | Method | URL | Request Parameter | Response |
---|---|---|---|---|
Delete Book by ID | DELETE | /deleteBookById/{id} | id (Path parameter) | 202 Accepted : Book deleted successfully OR 404 Not Found : Book with the given ID not found |
Delete Book by Name | DELETE | /deleteBookByName/{bookName} | bookName (Path parameter) | 202 Accepted : Books deleted successfully OR 404 Not Found : No books found with the given name |
Delete Books by Author | DELETE | /deleteAllByAuthor/{authorName} | authorName (Path parameter) | 202 Accepted : Books deleted successfully OR 404 Not Found : No books found with the given author name |
- Ensure you have Java and MySQL installed on your system.
- Clone or download the project from the repository.
- Import the project into your preferred IDE (e.g., Eclipse, IntelliJ).
- Set up the MySQL database and update the database configurations in the
application.properties
file (not provided in the code). - Build and run the project using the IDE or by running
mvn spring-boot:run
command from the project root directory.
- Java
- Spring Boot
- Spring Data JPA
- Hibernate
- RESTful API
- JSON
- MySQL
- PostMan (API Collection Documentation on Postman for testing API)
- Mavin
- You need to set up the database and make sure the application properties are correctly configured to run the project successfully.
Adding more features, error handling, authentication, and security measures.
Feel free to explore and use these project. If you encounter any issues or have suggestions for improvements, please feel free to contribute or reach out for assistance.
Contributions are always welcome! ✨
See contributing.md
for ways to get started.
Please adhere to this project's code_of_conduct.md
.
If you have any questions or would like to connect, please don't hesitate to reach out. I'd be more than happy to chat and learn from your experiences too.
Email: contact me
Thank you for taking the time to explore my project. I hope you find them informative and useful in your journey to learn Java and enhance your programming skills. Your support and contributions are highly appreciated.
Happy coding! ✨
- 🙍🏻♂️ @ajaynegi45
- 🙍🏻♂️ @LewisRye