Skip to content

Latest commit

 

History

History
160 lines (115 loc) · 4.83 KB

README.md

File metadata and controls

160 lines (115 loc) · 4.83 KB

EasyShop Ecommerce API

Welcome to the EasyShop Ecommerce API repository! This project is a comprehensive Java-based application designed to manage an ecommerce website's functionality.

Table of Contents

Features

  • Login / Register
    • Using SpringBoot JWT security, we are able to store users in the database with a hashed password.
  • Filtering Products
    • Using modules created from the front end, the API interacts with the database to retrieve relevant products.
      • Filter by Category
      • Filter by Min Price
      • Filter by Max Price
      • Filter by Color
  • Adding to cart
    • Logged in users are able to add items to their shopping cart.
      • The user cart is linked to their login, so it will be persistent even if they log out.
  • Order Processing
    • Create Orders: Generate new order based on the items in the user's shopping cart...

A Look Into the Application

File Structure / EasyShopApplication.java

image

SpringBoot AppConfig

image

Checkout the website!

Home page not logged in

This is the homepage when a user is not logged, in. They can view the products, but cannot add them to a cart.

image

Home page logged in

After logging in, a user is able to add items to their cart.

image

Cart

The user's current cart.

image

Checkout

Creating an order for the user based on items in the cart.

image

Clear

Clearing the cart if a user does not want to checkout.

image

File Structure / index.html

image

Interesting Piece of Code

I chose this piece of code because this post mapping checks the shopping cart to see whether an item is present, and if so it will update the quantity rather than a duplicate item.

@PostMapping("products/{product_id}")
    public ShoppingCart addItemToCart(Principal principal, @PathVariable int product_id) {
        try
        {
            // get the currently logged-in username
            String userName = principal.getName();
            // find database user by userId
            User user = userDao.getByUserName(userName);
            int userId = user.getId();

            ShoppingCart shoppingCart = getCart(principal);

            for (Map.Entry<Integer, ShoppingCartItem> item : shoppingCart.getItems().entrySet()) {
                if (item.getValue().getProductId() == product_id) {
                    shoppingCartDao.updateItemInCart(userId, product_id);
                    return getCart(principal);
                }
            }

            shoppingCartDao.addItemToCart(userId, product_id);

        }
        catch(Exception e)
        {
            throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Oops... our bad.");
        }
        return getCart(principal);
    }

Error Handling

Failure to load the cart

If there was an error trying to load the cart

.catch(error => {
	const data = {
		error: 'Load cart failed.',
	}

	templateBuilder.append('error', data, 'errors')
})

Error clearing the cart

If there was an error trying to clear the cart

.catch(error => {
	const data = {
		error: 'Empty cart failed.',
	}

	templateBuilder.append('error', data, 'errors')
})

Error checking out shopping cart

If there was an error checking out the user's shopping cart

.catch(error => {
	const data = {
		error: 'Empty cart failed.',
	}

	templateBuilder.append('error', data, 'errors')
})