Skip to content

nklimovych/book-store

Repository files navigation

'The Owly' bookstore

Hi there 👋

Welcome to the world of online book shopping, where stories come to life with just a click! 📚 This project isn't just any online bookstore, it's a dynamic platform crafted with Spring Boot magic, ready to whisk you away on a literary adventure.

Description

The Online Bookstore API isn't just a solution, it's a gateway to a realm of endless literary possibilities. 🌟 Seamlessly blending cutting-edge web technologies with industry best practices, this project sets the stage for a smooth and secure online book shopping experience.

Tech Stack:

  • Spring Boot: Your trusty steed for crafting Java-based web applications.
  • Spring Security: Guardian of the gates, ensuring only authorized users enter.
  • Spring Data JPA: Your faithful guide through the labyrinth of database interactions.
  • Spring Web: Your ticket to the world of web-based applications with Spring MVC.
  • Maven: Your organizational maestro, orchestrating dependencies with finesse.
  • Hibernate: The sorcerer's apprentice, wielding ORM magic.
  • Liquibase: The architect of database transformations, sculpting data with precision.
  • MySQL: Your sturdy stronghold, guarding precious data.
  • MapStruct: The cartographer, charting the territories of object mapping.
  • JUnit: Your trusty sword in the battle for code quality.
  • Mockito: The shape-shifter, conjuring illusions for seamless testing.
  • Docker: Your vessel for encapsulating the essence of your application.
  • Testcontainers: Your genie in a bottle, conjuring ephemeral environments for testing prowess.

Features:

  • User Registration and Authentication: Join the literary community with ease and security.
  • Book Browsing and Searching: Embark on a quest through the vast library of literature.
  • Shopping Cart Management: Gather your literary treasures with finesse.
  • Order Processing: Seal the deal and bring your chosen tales home.
  • User Profile Management: Customize your literary journey with personalized settings.
  • Secure RESTful API Endpoints: Fortified endpoints, ensuring safe passage for data travelers.

Demo video

Video Title

Installation

  1. Clone the repository:

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

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

    MYSQL_USER=root
    MYSQL_ROOT_PASSWORD=password
       
    MYSQL_DATABASE=bookstore
    MYSQL_LOCAL_PORT=3307
    MYSQL_DOCKER_PORT=3306
    
    SPRING_LOCAL_PORT=8080
    SPRING_DOCKER_PORT=8080
    DEBUG_PORT=5005
    
    JWT_SECRET=JustAnotherSuperSecretString1234!
    JWT_EXPIRATION=3600000
  3. Build and Run the Docker Containers:

    docker-compose up --build
  4. Access the Application:

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

  5. Stop and Remove Containers:

    To stop and remove the containers created by the Compose file, use the docker-compose down command:

    docker-compose down

Swagger Documentation

Explore the detailed API documentation generated by Swagger to understand the various endpoints and their functionalities.

How to Use JWT token to test endpoints with Swagger API (click to view)

Follow the next steps:

  • Open Auth Management registration endpoint: auth manager
  • Click on the "Try it out" button: auth manager
  • Register a new user with unique email and press "Execute" auth manager
  • If registration passes successfully, you'll see your registration data: auth manager
  • Open Auth Management login endpoint: auth manager
  • Click on the "Try it out" button: auth manager
  • Use registered login and password: auth manager
  • Copy token from response body: auth manager
  • Click on the "Authorize" button on the top of the page: auth manager
  • Paste the token in the field, and click "Authorize": auth manager
  • Now you can use all endpoints

🔐 Authentication Endpoints:

  • Register a new user: POST /api/auth/register
    {
      "email": "user@mail.com",
      "password": "password",
      "repeatPassword": "password",
      "firstName": "Owly",
      "lastName": "User",
      "shippingAddress": "Main St. 57, Lviv"
    }
  • Authenticate as user: POST /api/auth/login
     {
       "email": "user@mail.com",
       "password": "password"
     }
  • If you want to use admin endpoints, fill free to use credentials below:
     {
       "email": "admin@mail.com",
       "password": "password"
     }

📚 Book Endpoints

  • Retrieve book catalog: GET /api/books
  • Retrieve book details: GET /api/books/{id}
  • Create a new book: POST /api/books
  • Update a specific book: PUT /api/books/{id}
  • Delete a specific book: DELETE /api/books/{id}

📄 Category Endpoints

  • Create a new category: POST /api/categories
  • Retrieve all categories: GET /api/categories
  • Retrieve a specific category by its id: GET /api/categories/{id}
  • Update a specific category: PUT /api/categories/{id}
  • Delete a specific category: DELETE /api/categories/{id}
  • Retrieve books by a specific category: GET /api/categories/{id}/books

🛒 Shopping Cart Endpoints

  • Retrieve user's shopping cart: GET /api/cart
  • Add a book to the shopping cart: POST /api/cart
  • Update quantity of a book in the shopping cart: PUT /api/cart/cart-items/{cartItemId}
  • Remove a book from the shopping cart: DELETE /api/cart/cart-items/{cartItemId}

📦 Order Endpoints

  • Place an order: POST /api/orders
  • Retrieve user's order history: GET /api/orders
  • Retrieve all OrderItems for a specific order: GET /api/orders/{orderId}/items
  • Retrieve a specific OrderItem within an order: GET /api/orders/{orderId}/items/{itemId}
  • Update order status: PATCH /api/orders/{id}

👊 Faced Challenges

Challenge 1: Database Migrations

Problem: Managing database changes consistently across different environments.

Solution: Used Liquibase to automate database migrations.

Steps:

  • Created changelog files for database changes.
  • Configured Liquibase to run these changelogs during application startup.

Challenge 2: Dockerizing the Application

Problem: Ensuring consistent and reliable environments for development, testing, and production.

Solution: Used Docker to containerize the application and its dependencies.

Steps:

  • Created Dockerfiles to define the application and database images.
  • Used docker-compose to set up and manage a multi-container environment.
  • Tested the application in a Dockerized environment to ensure consistency across different stages.

🥷 Author: Nazar Klimovych | LinkedIn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published