Giter Club home page Giter Club logo

ms-focus's Introduction

MS Focus Shop

This app sets up a shop with products, special offers and delivery charges. It provides a Ruby API and also a Rails JSON API.

Ruby API

The Basket class provides a simple public API to add or remove line items, and query the total charge.

basket = Basket.new

basket.add('J01') # Alternatively: Basket.add('J01')
basket.add('B01')
basket.remove('J01')
 
basket.total
  => 2990

basket.formatted_total
  => "£29.90"

basket.line_items
  => [ ... ]

Rails JSON API

You can do the same actions as above using a JSON API.

POST /api/basket/add.json { code: 'J01' }
POST /api/basket/add.json { code: 'B01' }
POST /api/basket/remove.json { code: 'J01' }

GET /api/basket.json
  => {
       total: 2990,
       formatted_total: '£29.90',
       items: [ ... ]
     }

Thoughts for Improvement

  • For the purpose of this exercise, the basket and its line items are global. In a real world scenario the LineItem class would be specific to a user or session.
  • If offers conflict or have conditions, the system would need to be more intelligent to decide which one to pick.
  • Perhaps there might be more criteria for offers, e.g. fixed discount, a range of products, get a free other product, etc.
  • Given plenty more time, of course a single-page front end could also be created for the app.
  • Basket can start to get large and might need extracting out some concerns, e.g. setup is not really a concern of the Basket, and the total calculations could be moved to a Checkout class.

ms-focus's People

Watchers

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