Skip to content

k0sm0naft/java-online-book-store

Repository files navigation


Documentation License: MIT

📚 Welcome to Book Nook App

Book Nook App

In the digital age, online bookstores have revolutionized how we buy and sell books, offering unparalleled convenience and accessibility. Book Nook App was inspired by the need for a seamless, user-friendly backend platform where book lovers can discover, purchase, and manage their favorite reads.

Book Nook App addresses key challenges:

  • For Customers: Simplifies finding the right book with robust search and filter options, ensuring a smooth purchasing experience through an efficient order management system.
  • For Administrators: Provides comprehensive tools for inventory management, order tracking, and real-time updates, making it easy to manage an online bookstore.

Built with Spring Boot, Spring Security, Spring Data JPA, and Springdoc OpenAPI, Book Nook App offers a secure and robust backend, perfect for supporting the operations of an online bookstore.


📜 Table of Contents


📺Short Overview

Backend for Online Bookstore - Watch Video

✨Demo

How to use demo:

Use Swagger UI
  1. Open link.

  2. Open Authentication management Registration endpoint:

    Registration endpoint
  3. Click on "Try it out" button:

    Try it out button
  4. Register a new user (fill in a unique email) and "Execute":

    Register new user
  5. If you successfully registered, you'll see status code 201 with your registration data:

    Registration success
  6. Repeat steps 1-3 on Authentication management Login endpoint (use registered login and password).

  7. Copy token from response body:

    Copy token
  8. Click on the "Authorize" button on the top of the page, paste the token in the field, and click "Authorize":

    Authorize token
  9. Now you can use endpoints for users.

Use Postman collection

If you want to use manager's endpoints, fill free to use credentials below:

{
    "email":"[email protected]",
    "password":"12345678"
}

Note: The token expires after 1 hour, so you must log in again.


🛠️Technologies Used

  • Spring Boot: Framework for building Java-based web applications.
  • Spring Security: Provides authentication and authorization.
  • Spring Data JPA: Simplifies database interactions.
  • Spring Web: For building web-based applications with Spring MVC.
  • Springdoc OpenAPI: Generates API documentation.
  • MySQL: Database management system.
  • Hibernate: As the ORM tool.
  • Liquibase: Database migration tool.
  • MapStruct: Object mapping framework.
  • JUnit: Testing framework.
  • Mockito: Mocking framework for tests.
  • Maven: For project management and dependency management.
  • Testcontainers: Provides lightweight, throwaway instances of databases, selenium web servers, or anything else that can run in a Docker container.
  • Docker: Containerization platform.

🌎Features

📝Swagger Documentation

Swagger is integrated into the project to provide comprehensive API documentation and facilitate testing of endpoints. With Swagger, you can visualize and interact with the API's resources without having any of the implementation logic in place.

To access the Swagger UI and explore the API documentation:

Once the application is running, navigate to http://localhost:8080/api/swagger-ui/index.html in your web browser.

You will see the Swagger UI interface, where you can view all available endpoints, their descriptions, request parameters, and response schemas.

Use the interactive features of Swagger UI to make requests directly from the browser and observe the responses.

🔑Authentication

Authentication Endpoints: Users can register and log in.
  • Register a new user
    • Request: POST /api/auth/register
    • Response: 201 Created
  • Login a user
    • Request: POST /api/auth/login
    • Response: 200 OK with JWT token

📗Book

User's Endpoints: View and search books.
  • Get all books
    • Request: GET /api/books
    • Response: 200 OK
  • Get a book by ID
    • Request: GET /api/books/{id}
    • Response: 200 OK
  • Search books by params
    • Request GET /api/books/search
    • Response: 200 OK
Manager's and Admin's Endpoints: Add, update, and delete books.
  • Add a new book
    • Request POST /api/books
    • Response: 201 Created
  • Update a book
    • Request PUT /api/books/{id}
    • Response: 202 Accepted
  • Delete a book
    • Request DELETE /api/books/{id}
    • Response: 204 No Content

📑Category

User's Endpoints: View categories.
  • Get all categories
    • Request GET /api/categories
    • Response: 200 OK
  • Get a category by ID
    • Request GET /api/categories/{id}
    • Response: 200 OK
  • Get all books from category
    • Request GET /api/categories/{id}/books
    • Response: 200 OK
Manager's and Admin's Endpoints: Create, update, and delete book categories.
  • Add a new category
    • Request POST /api/categories
    • Response: 201 Created
  • Update a category
    • Request PUT /api/categories/{id}
    • Response: 202 Accepted
  • Delete a category
    • Request DELETE /api/categories/{id}
    • Response: 204 No Content

🛒Shopping Cart

User's Endpoints: Add books to the cart, view cart items, update and remove items from the cart.
  • Get current user's shopping cart
    • Request GET /api/cart
    • Response: 200 Ok
  • Add a book to the cart
    • Request POST /api/cart
    • Response: 201 Created
  • Update book quantity
    • Request PUT /api/cart/cart-items/{cartItemId}
    • Response: 202 Accepted
  • Remove a book from the cart
    • Request DELETE /api/cart/cart-items/{cartItemId}
    • Response: 204 No Content

🛍️Order

User's Endpoints: Complete the purchase, view past orders and their details.
  • Create order
    • Request POST /api/orders
    • Response: 201 Created
  • Get all orders for current user
    • Request GET /api/orders
    • Response: 200 Ok
  • Get an order details by ID
    • Request GET /api/orders/{orderId}/items
    • Response: 200 Ok
  • Get an ordered book details by ID
    • Request GET /api/orders/{orderId}/items/{id}
    • Response: 200 Ok
Manager's and Admin's Order Endpoints: Update order statuses.
  • Update order status
    • Request PATCH /api/orders/{id}
    • Response: 202 Accepted

🚀Setup Instructions

🧰Required

  • Docker
  • Docker Compose

🏗️Installation

  1. Clone the Repository:

    git clone https://github.com/k0sm0naft/java-online-book-store.git
    cd java-online-book-store
  2. Set Environment Variables:

    Create a .env file in the project root directory and populate it with the following environment variables:

    MYSQLDB_USER=your_db_user_name
    MYSQLDB_ROOT_PASSWORD=your_db_password
    JWT_SECRET=yourVeryLongSecretStringForJwtSecretKey
    JWT_EXPIRATION=3600000
    
    MYSQLDB_DATABASE=your_db_name
    MYSQLDB_LOCAL_PORT=3306
    MYSQLDB_DOCKER_PORT=3306
    
    SPRING_LOCAL_PORT=8080
    SPRING_DOCKER_PORT=8080
    DEBUG_PORT=5005
  3. Install dependencies and build the project:

    mvn clean install
  4. Build and Run the Docker Containers:

    docker-compose up
  5. Access the Application:

    Open your browser and go to http://localhost:8080/api/swagger-ui.html to access the Swagger API documentation.

  6. Stop and Remove Containers: To stop and remove the containers created by the Compose file, use the docker-compose down command:

     docker-compose down

🧪Running Tests

  • To run tests, use the following command:

    mvn test
  • Testing with JUnit and Mockito

  • The project uses JUnit for unit testing and Mockito for mocking dependencies. This ensures that the application logic is tested in isolation, making the tests more reliable and easier to maintain.


📬Postman Collection

To facilitate testing, a Postman collection has been provided. You can import it into Postman and use it to test the API endpoints.

Run in Postman

To chose URL:
  1. Click on API Collection.

  2. Go to Variables tab.

  3. Chose remote or local URL.

  4. Save changes.

    chose URL
  • After you fork collection, you can register a new user, or use credentials below in the text.
  • After log in, the generated token will be automatically added to all next requests that required authentication.
User
{
    "email": "[email protected]", 
    "password": "passExample123"
}
Manager
{
    "email":"[email protected]",
    "password":"12345678"
}

👊Challenges Faced

Security: Setting up robust authentication and authorization using Spring Security.

Database Management: Utilized Spring Data JPA and Hibernate for efficient database interactions and ORM capabilities.

Database Migrations: Implementing database migrations with Liquibase to ensure consistency across different environments.

API Documentation: Ensuring comprehensive API documentation with Springdoc OpenAPI.


👷Author


📝License

Copyright © 2024 Artem Akymenko.
This project is MIT licensed.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published