Skip to content

This API provides endpoints for managing books, users, and rental operations for a book rental service.

Notifications You must be signed in to change notification settings

Rajatsinha05/RentRead

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RentRead API

This API provides endpoints for managing books, users, and rental operations for a book rental service.

Tech Stack

  • 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

Setup

To set up and run the RentRead API locally, follow these steps:

  1. Clone the repository:
    git clone https://github.com/Rajatsinha05/RentRead.git
  2. Navigate to the project directory:
    cd RentRead
  3. Build the project using Gradle:
    gradle clean build
  4. Run
    ./gradlew bootRun

User Management

Register User

  • 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": []
      }

User Login

  • 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"

Book Management

Create Book

  • 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
      }

Get All Books

  • 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
        }
      ]

Update Book

  • 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
      }

Delete Book

  • Endpoint: DELETE /books/{id}
  • Description: Deletes a book from the system.
  • Response:
    • Status: 204 No Content

Rental Management

Rent Book

  • 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"
      }

Return Book

  • 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"
      }

Admin Operations

Add Book

  • 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
      }

Update Book (Admin Only)

  • 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
      }

Delete Book (Admin Only)

  • Endpoint: DELETE /books/{id}
  • Description: Deletes a book from the system. (Admin Only)
  • Response:
    • Status: 204 No Content

Sample User

For testing purposes, you can use the following sample user:

Admin User

You can also create an admin user with the following credentials:

  • First Name: Admin
  • Last Name: User
  • Email: admin

About

This API provides endpoints for managing books, users, and rental operations for a book rental service.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages