Coder Social home page Coder Social logo

interview-code-challenge's Introduction

README

Instructions

Prerequisites

  • Install Docker
  • Install Maven
  • Install Java 15
  • Start a local Docker repository: docker run -d -p 5000:5000 --restart=always --name registry registry:2

Compile

    mvn clean compile com.google.cloud.tools:jib-maven-plugin:3.0.0:dockerBuild

Run the app by using an IDE Like Intellij

If you are using Intellij just install all Maven dependencies and press the Play button to run the application.

Start the application With Docker

Just run a terminal session, go to the project folder and run:

docker-compose up -d

Considerations

The requirements could be understood in different ways, and I think this was part of the test. In my opinion the checkout event should be separated from the "change quantity event".

Change quantity could be refined even further in:

  • add a product;
  • remove a product;
  • change quantity;

Product removal should be triggered by the total absence of a SKU in the following body or by the quantity set to 0, just for the sake of having some flexibility.

{
  "products": {
    "044d2518-4ed0-4055-9821-e2608f6cf2e5": 110,
    "a70931cc-d7f3-4286-9ef0-c63fdeec3cb2": 200
  },
  "username": "foo"
}

I introduced a validation on the products so that products that are not in the products table cannot be added to the cart. The validation could be extended even further to check if a product is in stock.

Using CQRS, furthermore, it is not responsibility of the "checkout phase" endpoint to return the total price. So in my opinion the "checkout event" should only set a flag that "freezes" the cart waiting for the client to pay. For this reason I have created one more endpoint which can be called separately in order to retrieve the total price of the active cart before a checkout.

Having more time I would have plaid a bit with JMS and ActiveMQ, but it was overkill for the purpose of the test.

For the sake of the demo the username comes from the path in the request or from within the post object, obviously in a real scenario this would be inside a bearer token in the Authorization header, for further reference: https://leanpub.com/oauth2-ely5

The username is used in order to get the active cart. A user has always one cart in the ACTIVE state. When the cart is checked out this won't be deleted, it will be only flagged as checked out. This way we can extract important information from the carts: what kind of products a user likes, what his average spending is, etc..

As a final note the app was developed trying to follow DDD methodology.

The application will automatically create on load a test user and some demo products to start playing.

API Description

The application is available at http://localhost:8888, so I assume this is the base of my address.

Change quantity

Endpoint path: /cart/changequantity
Successful Response: 200
Request body:

{
  "products": {
    "044d2518-4ed0-4055-9821-e2608f6cf2e5": 110,
    "a70931cc-d7f3-4286-9ef0-c63fdeec3cb2": 200
  },
  "username": "foo"
}

Checkout

Endpoint path: /cart/checkout
Successful Response: 200
Request body:

{
  "username": "foo"
}

Get total price

Endpoint path: /cart/<username>/getcartinfo
Successful Response: 200
Request body:

{
  "userId": 1,
  "cartId": 1,
  "cartStatus": "ACTIVE",
  "totalFinalPrice": 19700.0,
  "products": [
    {
      "productId": 2,
      "productSku": "3779ebe8-cebd-438f-8399-59228739ed48",
      "minItemsForDiscount": 200,
      "numberOfFreeItems": 3,
      "quantity": 200,
      "stockQuantity": 400,
      "unitPrice": 100.0,
      "productName": "Rolex"
    }
  ]
}

interview-code-challenge's People

Contributors

deviad avatar

Watchers

 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.