Giter Site home page Giter Site logo

lana_test's Introduction

README

Requirements

  • Must have npm install on the machine (this will not be needed when dockerized)
  • The server was coded with nodejs version v14.4.0, but LTS should work just fine.
  • NPM version 6.14.4

First install the dependencies

  npm i

"DataBase" Data Model

The models were develop with a NoSQL implementation in mind, but it is very easy to implement a SQL dabase drive, as the main structure of the projects follows the Hexagonal architecture pradigm.

Products

Attributes:

  • code: Unique id
  • name: Product name
  • price: String based price
  • discount: Percentaje of total price to be discounted when applies
  • discountRule: Indicates the type of discount the products has
  • discountThreshold: Depending on the type, if is it "threshold", it will indicate how many items should add the customer in order to recieve the discount
 {
    "code": "PEN",
    "name": "Lan Pen",
    "price": "5.00€",
    "discount": 0.5,
    "discountRule": "two-one-free"
  },
  {
    "code": "TSHIRT",
    "name": "Lan T-Shirt",
    "price": "20.00€",
    "discount": 0.25,
    "discountRule": "threshold",
    "discounThreshold": 3
  },
  {
    "code": "MUG",
    "name": "Lan Coffee Mug",
    "price": "7.50€"
  },

Basket

Attributes:

  • items: Items snapshot, if the basket is purchased it will show the price at the time they were bought, if not they will be update whenever the basket is fetch.
  • itemsGroups: Groups items and aggregates its discounts and total price
  • checkoutTotal: It's the final basket amount, it's derived from the itemsGroups.
{
  "items": [
      {
          "code": "PEN",
          "name": "Lan Pen",
          "price": "5.00€",
          "discount": 0.5,
          "discountRule": "two-one-free",
          "currency": {
              "symbol": "",
              "name": "euro",
              "delimeter": ".",
              "nroDecimals": 2,
              "normalizedPrice": 500
          },
          "normPrice": 500
      }
  ],
  "itemsGroups": [
      {
          "code": "PEN",
          "unitPrice": 500,
          "total": 500,
          "discount": {
              "discount": 0.5,
              "unitPrice": 500
          },
          "totalDiscount": 0,
          "discountRule": "two-one-free",
          "quantity": 1
      }
  ],
  "checkoutTotal": 500,
  "id": "5a4d7012-80c2-4899-a961-3a049338fc2a"
}

Basket Routes

the project includes a postman collection that can be imported

// Create basket
POST -> /baskets

// Add product to basket
POST -> /baskets/:id/products

// Get basket checkout total
GET -> /baskets/:id/checkout/total

// Delete basket
DELETE -> /baskets/:id


//OTHERS

// Get All
GET -> /baskets

// Get By Id
GET -> /baskets/:id

Create a new checkout basket

Rest Client

POST -> localhost:4000/baskets

{
  "items": [
      {
          "code": "TSHIRT"
      }
  ]
}

Curl:

curl --location --request POST 'localhost:4000/baskets' \
--header 'Content-Type: application/json' \
--data-raw '{
  "items": [
      {
          "code": "TSHIRT"
      }
  ]
}'

Add a product to a basket

Rest Client

POST -> localhost:4000/baskets/5a4d7012-80c2-4899-a961-3a049338fc2a/products

{
    "code": "PEN"
}

Curl:

curl --location --request POST 'localhost:4000/baskets/5a4d7012-80c2-4899-a961-3a049338fc2a/products' \
--header 'Content-Type: application/json' \
--data-raw '{
    "code": "PEN"
}'

Get the total amount in a basket

Rest Client

GET -> localhost:4000/baskets/0826d750-310a-4c7f-85df-25d129dac5ca/checkout/total

{
    "code": "PEN"
}

Curl:

curl --location --request GET 'localhost:4000/baskets/0826d750-310a-4c7f-85df-25d129dac5ca/checkout/total'

Remove the basket

Rest Client

DELETE -> localhost:4000/baskets/5a4d7012-80c2-4899-a961-3a049338fc2a

{
    "code": "PEN"
}

Curl:

curl --location --request DELETE 'localhost:4000/baskets/5a4d7012-80c2-4899-a961-3a049338fc2a'

TODO

  • Server side.
  • Required endpoints
  • Products and basket business logic
  • Client side.
  • Add some error handling to the server.
  • Add in server documnetation like swagger.
  • Add unit and integration tests.
  • Dockerize client and server.
  • Stress and performance test with locust.

lana_test's People

Contributors

jcardenaslie avatar

Watchers

James Cloos avatar  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.