Giter Club home page Giter Club logo

flip-shop's Introduction

Flip-shop

Simple online shopping application. Support Items, Promotions and Cart management.

Domain model

Cart

Describes the Cart by managing Items Purchased and the total price of items.

Cart Status

  • A new Carts has status Available.
  • Carts with status Available can receive Item purchases, or be Submitted.
  • Submitted Cart cannot receive Item purchases.
  • Submitted a Cart will apply promotions to purchased items and remove purchased Item from being available.

Item

Describes the items available for purchase.

Item availability and reservation

  • Only a given quantity of an Item is available for shopping.

  • Adding Items to a Cart reserves the Item quantity. Reserved Item quantities are not available for shopping until removed from a Cart.

Promotion

Describes the Promotions affecting a Cart, depending on the Items present in the Cart.

Cart update from applied promotions

Promotions can change a Cart by:

  • Adding and Item quantity to a Cart.
  • Adding a discount to an Item purchased.

REST API

POST /cart

Create and available Cart

Response Payload

{
    "CartID": "d6870d29-eb07-4a31-9469-abe898183a1c",
    "Purchases": {},
    "CartStatus": "Available",
    "Total": 0
}

[PUT | DELETE] /cart/{cartID}/purchase

  • PUT: Purchase an Item and add it to the Cart
  • DELETE: Remove a Purchased Item from the Cart

Request Payload

{
    "sku":"120P90",
    "qty": 3
}

Response Payload

{
    "CartID": "d6870d29-eb07-4a31-9469-abe898183a1c",
    "Purchases": {
        "120P90": {
            "Sku": "120P90",
            "Name": "Google Home",
            "Price": 4999,
            "Qty": 3,
            "Discount": 0
        }
    },
    "CartStatus": "Available",
    "Total": 0
}

PUT cart/{cartID}/status/submitted

Submit the Cart by applying promotions and calculating the total

Response Payload

{
    "CartID": "d6870d29-eb07-4a31-9469-abe898183a1c",
    "Purchases": {
        "120P90": {
            "Sku": "120P90",
            "Name": "Google Home",
            "Price": 4999,
            "Qty": 3,
            "Discount": 4999
        },
        "234234": {
            "Sku": "234234",
            "Name": "Raspberry Pi B",
            "Price": 3000,
            "Qty": 2,
            "Discount": 6000
        },
        "43N23P": {
            "Sku": "43N23P",
            "Name": "MacBook Pro",
            "Price": 539999,
            "Qty": 2,
            "Discount": 0
        },
        "A304SD": {
            "Sku": "A304SD",
            "Name": "Alexa Speaker",
            "Price": 10950,
            "Qty": 4,
            "Discount": 4380
        }
    },
    "CartStatus": "Submitted",
    "Total": 1129416
}

Considerations

Project organization

  • /utils: external utilities
  • /internal/model: domain models
  • /internal/repo: repositories
  • /internal/route: HTTP handlers, and domain service logic (** handlers and service logic could be separated ideally **)

Memory key/value database

  • The application uses a basic memory Key/Value database, in /utils/memdb
  • It implements an ACID isolation level of "Serializable" by mutex locking the map stored in memory
  • It ** does not implement transaction rollback ** for the sake of demo simplicity (no time for this now)

Unit testes

  • Most of the domain models have unit tests.
  • Repositories and HTTP handlers are missing unit tests

flip-shop's People

Contributors

gambarini 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.