Skip to content

nguyenhuy158/springcommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringCommerce

Problem statement

A small start-up named "SpringCommerce" wants to build a very simple online shopping application to sell their products. In order to get to the market quickly, they just want to build an MVP (Minimum Viable Product) version with a very limited set of functionalities:

Requirement

click here to detail

SOlUTION

  • Entity-relationship diagram

    • Diagram db
  • A brief explanation for software development principles, patterns and practices being applied.

    • SOLID principles: Exhibited here

      • S: Single Responsibility Principle is exhibited here in that a controller should handle a specific HTTP request and respond with a corresponding HTTP response.
      • L: Liskov Substitution Principle is exhibited by the UserDetailImp objects being inherited from the UserDetail class.
      • D: Dependency Inversion Principle is exhibited by the use of dependency injection of spring boot.
    • MVC pattern:

      • Exhibited here in that the source code structure is divided into 3 parts CONTROLLER responsible for accepting requests from the user, service responsible for processing business tasks by calling and integrating the corresponding repository to manipulate the database, VIEW shown in HTML files to render and display to the user, MODEL shown in specific managed objects such as entities.
  • A brief explanation for the code structure.

    The code structure follows the Model-View-Controller (MVC) architectural pattern, which separates the application into three main components:

  1. Model: This component is responsible for managing the data of the application. It includes entities, repositories, and services that interact with the database.
| - model
|   | - entities
|   | - repositories
|   | - services
  1. View: This component is responsible for rendering the user interface of the application. It includes HTML, CSS, and JavaScript files that are served to the client's browser.

    | - resources
    |   | - static
    |   |   | - js
    |   |   |   | - *.js
    |   |   | - css
    |   |   |   | - *.css
    |   | - templates
    |   |   | - *.html
    
  2. Controller: This component acts as an intermediary between the Model and View components. It receives user requests, processes them, and returns responses. It includes controllers that handle HTTP requests and map them to the appropriate service methods.

    | - controller
    |   | - *Controller.java
    
  • All required steps in order to get the application run on a local computer.

    To run the application on a local computer, please follow the steps below:

  1. Download and install version 17 of the Java Development Kit (JDK) on your computer. The download link can be found at https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html.
  2. Download and install Docker from https://www.docker.com/products/docker-desktop/.
  3. Download and install Visual Studio Code (vscode) from https://code.visualstudio.com/download.
  4. Download and enable the Spring Boot Extension Pack extension in vscode. The extension can be downloaded from https://marketplace.visualstudio.com/items?itemName=vmware.vscode-boot-dev-pack.
  5. Download and enable the Extension Pack for Java extension in vscode. The extension can be downloaded from https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack.
  6. Download the source code from https://github.com/nguyenhuy158/springcommerce and open it in vscode.
  7. Run the docker-compose.yml file located at /src/main/resources/docker-compose.yml using the command docker compose up -d.
  8. Press ctrl + shift + p in vscode and enter Spring Boot Dashboard:run.... The application should now be running.
  • Full CURL commands or Postman snapshots to verify the APIs (include full request endpoints, HTTP Headers and request payload if any).

Table of APIs


URL METHOD IMAGE DESCRIPTION
/api/products GET image Get all products
/api/products?name=x GET image Get products with name containing 'x'
/api/products POST image Create a new product
/api/products DELETE image Delete all products
/api/products/id DELETE image Delete product by ID
/api/products/id GET image Get product by ID
/api/products/id PUT image Update product by ID
/api/products/id/orders GET image Get orders containing product with ID
/api/products/id/orders POST image Add product with ID to cart
/api/products/id/orders/id DELETE image Remove product with ID from cart with ID

URL METHOD IMAGE DESCRIPTION
/api/orders GET image Get all orders
/api/orders POST image Create a new order
/api/orders/id GET image Get order by ID
/api/orders/id PUT image Update order by ID
/api/orders/id DELETE image Delete order by ID
/api/orders/id/products GET image View products in order with ID.

Some product photos.

Video Demo

About

HK2_JavaTechnology_Midterm_SpringCommerce

Resources

Stars

Watchers

Forks