Skip to content

kundanpure/bookstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Bookstore RESTful API

A robust and modular RESTful API for a Bookstore application, built using Java Spring Boot as part of a backend developer assignment. This API enables book and user management with features like JWT authentication, CRUD operations, filtering, search, pagination, and interactive Swagger documentation.


πŸš€ Tech Stack

  • Language: Java 17+
  • Framework: Spring Boot
  • Database: MySQL
  • ORM: JPA/Hibernate
  • Authentication: JWT (JSON Web Tokens)
  • Documentation: Swagger / OpenAPI (Springdoc)
  • Dependencies: Lombok, Spring Security, Spring Data JPA, MySQL Driver

πŸ“· Postman / Swagger Screenshots

πŸ” Signup

Signup

πŸ” Login

Login

πŸ“– Get Book By ID

Book By ID

πŸ—‘οΈ Delete Book

Delete Book

πŸ” Search Book

Search Book

⚠️ Exception Handling (Invalid Book ID)

Exception

πŸ“‘ Swagger UI

Swagger

πŸ•΅οΈ Other Screens

Screen 1
Screen 2
Screen 3

βœ… Features

πŸ” User Authentication

  • Signup & Login with JWT-based authentication.
  • Secure protected routes using tokens.

πŸ“– Books API

  • Full CRUD for books.
  • Filter books by author, category, and rating.
  • Search books by title (partial match supported).

πŸ›‘οΈ Error Handling

  • Proper HTTP status codes (400, 401, 404, etc.)
  • Input validation for all endpoints.

✨ Bonus Features

  • Pagination: Paginated book listing with sorting support.
  • Swagger UI: Live API docs at /swagger-ui.html.
  • Clean Architecture: Services, controllers, DTOs, repositories, and security are modularly separated.

βš™οΈ Prerequisites

  • Java 17+
  • MySQL installed and running
  • Maven installed
  • Postman (optional, for testing with screenshots)

πŸ› οΈ Setup Instructions

1. Clone the Repository

git clone <repository-url>
cd bookstore

2. Configure MySQL Database

Create a database:

CREATE DATABASE bookstore_db;

Update src/main/resources/application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/bookstore_db
spring.datasource.username=<your-username>
spring.datasource.password=<your-password>

3. Build & Run the Application

mvn clean install
mvn spring-boot:run

App starts at: http://localhost:8080


πŸ“˜ Access Swagger UI

Navigate to:

http://localhost:8080/swagger-ui.html

Explore and test endpoints interactively!


πŸ“‘ API Endpoints

πŸ” Authentication

1. User Signup

  • POST /api/auth/signup
{
  "email": "user@example.com",
  "password": "password123"
}

2. User Login

  • POST /api/auth/login
{
  "email": "user@example.com",
  "password": "password123"
}

βœ… Response includes a JWT Token to use as Authorization: Bearer <token>


πŸ“˜ Books API (All Protected Routes)

3. Create a Book

  • POST /api/books
{
  "title": "The Great Gatsby",
  "author": "F. Scott Fitzgerald",
  "category": "Fiction",
  "price": 10.99,
  "rating": 4.5,
  "publishedDate": "1925-04-10"
}

4. Get All Books

  • GET /api/books

5. Get Book by ID

  • GET /api/books/{id}

6. Update Book

  • PUT /api/books/{id}

7. Delete Book

  • DELETE /api/books/{id}

8. Filter Books

  • GET /api/books/filter?author=<author>&category=<category>&rating=<rating>

Example:

/api/books/filter?author=Fitzgerald&category=Fiction&rating=4

9. Search Books by Title

  • GET /api/books/search?keyword=<keyword>

Example:

/api/books/search?keyword=Gatsby

10. Paginated Books

  • GET /api/books/paginated?page=<page>&size=<size>&sortBy=<field>

Example:

/api/books/paginated?page=0&size=5&sortBy=price

πŸ“· Postman Screenshots

Located in the screenshots/ folder:

  • signup.png – User signup
  • login.png – User login (JWT)
  • create-book.png – Book creation
  • get-all-books.png – Fetch all books
  • filter-books.png – Filter books

πŸ“Œ Assumptions

  • All book-related APIs require JWT authentication.
  • Rating must be a value between 0 and 5.
  • Pagination defaults: page=0, size=5, sortBy=price.
  • MySQL is the default DB (adjustable in application.properties).

✨ Enhancements

  • Swagger UI for easy testing and understanding.
  • Paginated + sorted responses for large datasets.
  • Flexible filtering with custom repository queries.

🧠 Project Structure

bookstore/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/com/bookstore/bookstore/
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/     # REST Controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # DTOs
β”‚   β”‚   β”‚   β”œβ”€β”€ entity/         # Entities
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/     # JPA Repositories
β”‚   β”‚   β”‚   β”œβ”€β”€ security/       # JWT & Security Config
β”‚   β”‚   β”‚   └── service/        # Business Logic
β”‚   └── resources/
β”‚       └── application.properties
└── pom.xml

πŸ§ͺ How to Test

  • Start the app.
  • Use Postman or Swagger UI to hit the endpoints.
  • Refer to screenshots for sample requests.

πŸ“€ Submission

  • GitHub: Share the public repo URL
  • ZIP: Or package and upload the project directory

Built with ❀️ for learning, growth, and backend excellence.

About

Assignment to access my backend skill in java spring boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages