Skip to content

Latest commit

 

History

History
151 lines (125 loc) · 2.42 KB

README.md

File metadata and controls

151 lines (125 loc) · 2.42 KB

Shopping Cart

A simple REST application with Kotlin

Stack

Building Application

./gradlew clean build

Testing Application

./gradlew clean test

Minimum coverage is 80%, and report in build/jacocoHtml/index.html

Running Sonarqube locally

./gradlew clean test sonarqube \
  -Dsonar.projectKey=<<your-project-key-configured>> \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=<<the-login>>

Running Application

java -jar build/libs/shopping-cart-<version>.jar

Application's Swagger

http://localhost:8000/swagger-ui.html

Operations

Create a cart associated to a user

curl -X 'POST' \
  'http://localhost:8000/cart' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "user_id": "123"
}'
{
  "user_id": "123",
  "products": []
}

Get a cart associated to a user

curl -X 'GET' \
  'http://localhost:8000/cart/user/123' \
  -H 'accept: application/json'
{
  "user_id": "123",
  "products": []
}

Add a product to a cart

curl -X 'POST' \
  'http://localhost:8000/cart/user/123/products' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": 1,
  "quantity": 1
}'
{
  "user_id": "123",
  "products": [
    {
      "id": 1,
      "name": "Shorts",
      "price": 55,
      "description": "",
      "category": "Clothes",
      "quantity": 1
    }
  ]
}

Create a product

curl -X 'POST' \
  'http://localhost:8000/product' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Sneakers",
  "price": 199.99,
  "description": "A blue sneaker",
  "category": "Clothes"
}'
{
  "id": 4,
  "name": "Sneakers",
  "price": 199.99,
  "description": "A blue sneaker",
  "category": "Clothes"
}

Get a product by id

curl -X 'GET' \
  'http://localhost:8000/product/4' \
  -H 'accept: application/json'
{
  "id": 4,
  "name": "Sneakers",
  "price": 199.99,
  "description": "A blue sneaker",
  "category": "Clothes"
}