This API provides endpoints for managing books, users, and rental operations for a book rental service.
- Java: Core programming language
- Spring Boot: Framework for building the application
- Spring Security: For authentication and authorization
- Gradle: Build automation tool
- MySQL: Database management system
- Hibernate: ORM (Object-Relational Mapping) framework
To set up and run the RentRead API locally, follow these steps:
- Clone the repository:
git clone https://github.com/Rajatsinha05/RentRead.git
- Navigate to the project directory:
cd RentRead
- Build the project using Gradle:
gradle clean build
- Run
./gradlew bootRun
- Endpoint:
POST /user/register
- Description: Registers a new user in the system.
- Request Body:
{ "firstName": "Rajat", "lastName": "Sinha", "email": "rajat.sinha@example.com", "password": "password123", "role": "USER" }
- Response:
- Status: 201 Created
- Body:
{ "id": 1, "firstName": "Rajat", "lastName": "Sinha", "email": "rajat.sinha@example.com", "role": "USER", "books": [] }
- Endpoint:
POST /user/login
- Description: Authenticates a user and returns an access token.
- Request Body:
{ "email": "rajat.sinha@example.com", "password": "password123" }
- Response:
- Status: 200 OK
- Body:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
- Endpoint:
POST /books
- Description: Adds a new book to the system.
- Request Body:
{ "title": "Sample Book", "author": "Jane Smith", "genre": "Thriller", "available": true }
- Response:
- Status: 201 Created
- Body:
{ "id": 1, "title": "Sample Book", "author": "Jane Smith", "genre": "Thriller", "available": true }
- Endpoint:
GET /books
- Description: Retrieves all books in the system.
- Response:
- Status: 200 OK
- Body:
[ { "id": 1, "title": "Sample Book", "author": "Jane Smith", "genre": "Thriller", "available": true }, { "id": 2, "title": "Another Book", "author": "John Doe", "genre": "Mystery", "available": false } ]
- Endpoint:
PUT /books/{id}
- Description: Updates information about a specific book.
- Request Body:
{ "title": "Updated Book Title" }
- Response:
- Status: 200 OK
- Body:
{ "id": 1, "title": "Updated Book Title", "author": "Jane Smith", "genre": "Thriller", "available": true }
- Endpoint:
DELETE /books/{id}
- Description: Deletes a book from the system.
- Response:
- Status: 204 No Content
- Endpoint:
POST /books/rent/{id}
- Description: Allows a user to rent a book.
- Request Body:
{ "userId": 123 }
- Response:
- Status: 200 OK
- Body:
{ "firstName": "Rajat", "lastName": "Sinha", "email": "rajat.sinha@example.com", "books": [ { "id": 1, "title": "Sample Book", "author": "Jane Smith", "genre": "Thriller", "available": false } ], "role": "USER" }
- Endpoint:
POST /books/return/{id}
- Description: Allows a user to return a rented book.
- Request Body:
{ "userId": 123 }
- Response:
- Status: 200 OK
- Body:
{ "firstName": "Rajat", "lastName": "Sinha", "email": "rajat.sinha@example.com", "books": [], "role": "USER" }
- Endpoint:
POST /books
- Description: Adds a new book to the system. (Admin Only)
- Request Body:
{ "title": "New Book", "author": "Admin Author", "genre": "Fiction", "available": true }
- Response:
- Status: 201 Created
- Body:
{ "id": 3, "title": "New Book", "author": "Admin Author", "genre": "Fiction", "available": true }
- Endpoint:
PUT /books/{id}
- Description: Updates information about a specific book. (Admin Only)
- Request Body:
{ "title": "Updated Book Title" }
- Response:
- Status: 200 OK
- Body:
{ "id": 1, "title": "Updated Book Title", "author": "Jane Smith", "genre": "Thriller", "available": true }
- Endpoint:
DELETE /books/{id}
- Description: Deletes a book from the system. (Admin Only)
- Response:
- Status: 204 No Content
For testing purposes, you can use the following sample user:
- First Name: Rajat
- Last Name: Sinha
- Email: rajat.sinha@example.com
- Password: password123
- Role: USER
You can also create an admin user with the following credentials:
- First Name: Admin
- Last Name: User
- Email: admin