Skip to content

RentRead is a Spring Boot–based RESTful API for an online book rental platform, implementing secure authentication, role-based authorization, and complete rental workflows. Built with a clean layered architecture and MySQL persistence, it demonstrates real-world backend best practices, robust error handling, and fully tested business logic.

Notifications You must be signed in to change notification settings

pushpak90/RentRead

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

📚 RentRead – Online Book Rental System (Spring Boot)

RentRead is a RESTful API built using Spring Boot for managing an online book rental system. It supports user authentication, role-based authorization, book management, and rental workflows with MySQL persistence.

The application follows a layered architecture and is designed according to real-world backend best practices.


🚀 Features

🔐 Authentication & Authorization

  • Basic Authentication (email + password)
  • Passwords encrypted using BCrypt
  • Role-based access:
    • ADMIN
    • USER

👤 User Management

  • User registration (default role: USER)
  • Admin registration
  • User login using email and password

📖 Book Management

  • Admin can:
    • Create books
    • Update books
    • Delete books
  • Users and Admins can:
    • View all available books

🔁 Rental Management

  • Users can rent books
  • A user can have maximum 2 active rentals
  • Users can return books
  • Book availability updates automatically

⚠️ Error Handling

  • Centralized global exception handling
  • Proper HTTP status codes (400, 401, 403, 404)
  • Consistent error response structure

🧪 Testing

  • Automated tests using MockMvc and Mockito
  • All assessment test cases passing

🛠 Tech Stack

  • Java 17
  • Spring Boot 3
  • Spring Security (Basic Auth)
  • Spring Data JPA
  • Hibernate
  • MySQL
  • H2 Database (for tests)
  • Lombok
  • Gradle

📂 Project Structure

src
├── main
│   ├── java/com/crio/rent_read
│   │   ├── config
│   │   ├── controller
│   │   ├── dto
│   │   ├── entity
│   │   ├── exception
│   │   ├── repository
│   │   ├── security
│   │   ├── service
│   │   ├── service/impl
│   │   └── util
│   └── resources
│       └── application.properties
└── test
    └── java/com/crio/rent_read

⚙️ Configuration

application.properties

spring.application.name=rent_read
server.port=8081

spring.datasource.url=jdbc:mysql://localhost:3306/test_db
spring.datasource.username=assessment
spring.datasource.password=redrum

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

⚠️ Automated tests run on H2 in-memory database, not MySQL.


▶️ Running the Application

Build

./gradlew clean build

Run

./gradlew bootRun

OR using JAR

java -jar build/libs/rent_read-0.0.1-SNAPSHOT.jar

Application runs on:

http://localhost:8081

🔑 API Endpoints

🟢 Authentication APIs (Public)

Create User / Admin

POST /auth/signup
{
  "email": "admin@rentread.com",
  "password": "admin123456",
  "firstName": "Admin",
  "lastName": "User",
  "role": "ADMIN"
}

Login

POST /auth/login

📘 Book APIs

Endpoint Method Access
/books GET USER, ADMIN
/books POST ADMIN
/books/{id} PUT ADMIN
/books/{id} DELETE ADMIN

🔁 Rental APIs

Endpoint Method Description
/rentals/users/{userId}/books/{bookId} POST Rent a book
/rentals/active-rentals/users/{userId} GET Get active rentals
/rentals/{rentalId} PUT Return a book

🧪 Sample cURL Commands

Create Admin

curl -X POST http://localhost:8081/auth/signup -H "Content-Type: application/json" -d '{"email":"admin@rentread.com","password":"admin123456","firstName":"Admin","lastName":"User","role":"ADMIN"}'

Create User

curl -X POST http://localhost:8081/auth/signup -H "Content-Type: application/json" -d '{"email":"user.test@example.com","password":"user123456","firstName":"Test","lastName":"User"}'

Login

curl -X POST http://localhost:8081/auth/login -H "Content-Type: application/json" -d '{"email":"user.test@example.com","password":"user123456"}'

Create Book (ADMIN)

curl -u admin@rentread.com:admin123456 -X POST http://localhost:8081/books -H "Content-Type: application/json" -d '{"title":"Test Book","author":"Author","genre":"FICTION","availabilityStatus":"AVAILABLE"}'

Rent Book (USER)

curl -u user.test@example.com:user123456 -X POST http://localhost:8081/rentals/users/1/books/1

❗ Rental Limit Enforcement

{
  "message": "User has already reached maximum book rental limit!",
  "httpStatus": "BAD_REQUEST",
  "localDateTime": "2025-03-10T21:10:53.9228473"
}

✅ Assessment Checklist

  • ✔ Authentication & Authorization implemented
  • ✔ Role-based access control
  • ✔ Rental limit enforced
  • ✔ Centralized error handling
  • ✔ Tests passing
  • ✔ Clean layered architecture
  • ✔ Ready for submission

About

RentRead is a Spring Boot–based RESTful API for an online book rental platform, implementing secure authentication, role-based authorization, and complete rental workflows. Built with a clean layered architecture and MySQL persistence, it demonstrates real-world backend best practices, robust error handling, and fully tested business logic.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published