Giter VIP home page Giter VIP logo

demooneboxcart's Introduction

Challenge Test Onebox

by Brando Palacios

Description Project

The service is presented using a variant of the MVC architecture applying different tools that allow easy testing of the challenge. For this we use an in-memory H2 database and documentation using Swagger. We opted for the use of Java 17 as a test implementation.

Getting Started

Reference Dependencies

We used java version 17 using the following dependencies:

  • Spring Boot 3.0.4
  • Apache Maven 3.8.7
  • H2 Database
  • MyBatis
  • Lombok
  • Swagger

How to run the project

  1. Clone the repository
  2. Build the project with mvn command: mvn clean install
  3. Run the project with mvn command: mvn spring-boot:run
  4. You can test the endpoints using the swagger interface go to the following url: http://localhost:8080/swagger-ui/index.html#/

How to run the tests

  • Run the tests with mvn command: mvn test

Endpoints

Cart Controller

Cart is an online shopping cart concept commonly used in ecommerce services, in which we store our list of desired products, therefore we use the following endpoints to manipulate the cart.

GET /cart (Get all carts)
Get all active carts in list
Parameters

None

Responses
{
  "carts": [
    {
      "id": "3c11c6f4-b7cf-4feb-88ab-50f9b196f679",
      "totalPrice": 34.3,
      "productListIds": [
        1
      ],
      "creationUser": "bpalaciosm",
      "modificationUser": "bpalaciosm",
      "creationDate": "2023-05-03T07:08:25.909531",
      "modificationDate": "2023-05-03T07:08:25.909531"
    }
  ]
}
Example cURL
curl -X 'GET' \
  'http://localhost:8080/cart' \
  -H 'accept: application/hal+json'
POST /cart (Create new shopping cart)
Create a new cart with a list of products. These products must already exist in the database.
Parameters

None

Request Body
{
  "productListIds": [
    1
  ],
  "creationUser": "onebox"
}
Responses (200)
{
  "id": "308e0332-7c16-4ed8-9570-e8ed9517dc49"
}
Example cURL
curl -X 'POST' \
  'http://localhost:8080/cart' \
  -H 'accept: application/hal+json' \
  -H 'Content-Type: application/json' \
  -d '{
  "productListIds": [
    1
  ],
  "creationUser": "onebox"
}'
GET /cart/{id} (Get cart information)
Get cart information by generated id
Parameters
  • id : String [Example: 3c11c6f4-b7cf-4feb-88ab-50f9b196f679]
Responses
{
  "id": "3c11c6f4-b7cf-4feb-88ab-50f9b196f679",
  "totalPrice": 34.3,
  "productListIds": [
    1
  ],
  "creationUser": "bpalaciosm",
  "modificationUser": "bpalaciosm",
  "creationDate": "2023-05-03T07:08:25.909531",
  "modificationDate": "2023-05-03T07:08:25.909531"
}
Example cURL
curl -X 'GET' \
  'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
  -H 'accept: application/hal+json'
PUT /cart/{id} (Put or Drop products from cart)
Enpoint in charge of removing or putting products in the cart and updating to the latest modification. For this we use the flag addToCart that will indicate if it is placing or removing products. During this process the cart will be updated with the total price.
Parameters
  • id : String [Example: 3c11c6f4-b7cf-4feb-88ab-50f9b196f679]

Case 1 (Drop Product):

Request Body
{
  "productListIds": [
    1
  ],
  "addToCart": false,
  "modificationUser": "user"
}
Responses (200)
{}

Case 2 (Add Product):

Request Body
{
  "productListIds": [
    1
  ],
  "addToCart": true,
  "modificationUser": "user"
}
Responses (200)
{}
Example cURL
curl -X 'PUT' \
  'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
  -H 'accept: application/hal+json' \
  -H 'Content-Type: application/json' \
  -d '{
  "productListIds": [
    1
  ],
  "addToCart": false,
  "modificationUser": "user"
}'
DELETE /cart/{id} (Get cart information)
Delete cart by id
Parameters
  • id : String [Example: 3c11c6f4-b7cf-4feb-88ab-50f9b196f679]
Responses (200)
{}
Example cURL
curl -X 'DELETE' \
  'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
  -H 'accept: application/hal+json'

Product Controller

Every cart has products for purchase, these products are listed and well labeled according to the catalog that has our platform.

GET /product (Get all products)
Get all list of products in database
Parameters

None

Responses
{
  "products": [
    {
      "id": 1,
      "description": "Product 1",
      "price": 1
    }
  ]
}
Example cURL
curl -X 'GET' \
  'http://localhost:8080/product' \
  -H 'accept: application/hal+json'
POST /product/{id} (Create new product)
Create new product in database
Parameters

None

Request Body
{
  "description": "Product 2",
  "price": 10.3
}
Responses
{
  "id": 2
}
Example cURL
curl -X 'POST' \
  'http://localhost:8080/product' \
  -H 'accept: application/hal+json' \
  -H 'Content-Type: application/json' \
  -d '{
  "description": "Product 2",
  "price": 10.3
}'
GET /product/{id} (Get product information)
View specific product
Parameters
  • id : String [Example: 3c11c6f4-b7cf-4feb-88ab-50f9b196f679]
Responses
{
  "id": 1,
  "description": "Product 1",
  "price": 1
}
Example cURL
curl -X 'GET' \
  'http://localhost:8080/product/1' \
  -H 'accept: application/hal+json'

Screeshot Evidence

SwaggerUI

OpenAPIv3 was used to launch our documentation.

Dont

Scheduling Task

A task is set every 10 minutes to check that no car has expired, otherwise it deletes it. This can be found in the JobConfiguration.java file.

Give

Test Success

Nine tests were performed and were satisfactory.

Up

demooneboxcart's People

Contributors

brandpm18 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.