Coder Social home page Coder Social logo

tarnas-vouchers's Introduction

Tarnas vouchers

why

This is a training application. The point of doing this was to see if I can reliably put something together using nodejs and react and deploy it. Functional specification is as follows:

Target: Application managing vouchers (promotion codes)

Context: as a retail shop you want to use an application managing vouchers. your clients can use vouchers (generated by me in the voucher system). my retail shop will take the voucher from enduser and verify its validity against the voucher system and get the information about the discount from that system.

Functional specification:

  • api is secured
  • creating n (1 <= n <= 1k) in a campaign
  • peeping at the voucher by its id
  • using the voucher by its id

GUI client

  • a simple application showing 3 hardcoded products. when you choose to buy a product, you input your voucher code, it is validated and the discount is applied to the item. buying said item results in using the voucher in the management system
  • presentation layer - basic

domain:

Voucher

  • has unique id (containing Campaign prefix)
  • discount - percentage or flat value
  • can be used once or multiple times

Campaign

  • can expire
  • campaign id is a prefix for voucher ids

solution

server

api

Voucher resources are available under /api/vouchers

to create vouchers:

POST /api/vouchers

payload:
{
  "campaign": "WOW_IN_CLOUD_ON_HEROKU",
  "discountType":  0, // 0 for percentage, 1 for flat discount
  "discountValue": 2,
  "uses": 666, // how many times the voucher(s) can be used, default is 0
  "count": 2 // how many vouchers should be created
}

the system responds with a 201 Created response along with an array of voucher codes that were created in the system

to peep at voucher:

GET /api/voucher/{voucherCode} voucherCode should be the full voucherCode generated by the system (returned when creating vouchers)

example response:
{
    "campaign": "WOW_IN_CLOUD_ON_HEROKU",
    "code": "WOW_IN_CLOUD_ON_HEROKU_58ab66afdbcb3a00211b3417",
    "discountValue": 2,
    "discountType": 0,
    "usable": true
}

to use up the voucher: POST /api/voucher/{voucherCode} voucherCode should be the full voucherCode generated by the system (returned when creating vouchers) the system returns 204 No Content on success

campaigns

any string campaign value provided during voucher creation will be used as campaign prefix, however some expiring campaigns have been defined (see: hardcoded) in the server to allow for creating vouchers usable only during specific time of the year 2017. Dates you see here are inclusive when checking voucher validity

  • XMAS: from 2017-11-12 to 2017-12-25
  • SNOWBOARD_SALE: from 2017-06-01 to 2017-08-31
  • HALLOWEEN: from 2017-02-14 to 2017-11-01

'security'

authorization is very naive - a specific header (Super-Secret-Authorization-Key) must be set to a specific value (mellon) for the api to recognized the request as authorized

server is also cors enabled

client

example SPA client is hosted at the root of the application.

basic happy path implemented: user clicks 'buy' on one product -> inserts voucher -> clics 'use voucher' -> discount is applied on dialog after checking if voucher is valid -> user clicks 'BUY' -> voucher is used up in the system -> item is set as 'sold'

the GUI also handles situation where user provides invalid voucer, displaying an appropriate error message

error handling for unavailability of the api is in place

GUI client does not save any state - after reloading the application items can be purchased again, however old vouchers cannot be used as that state is retained on the server

tarnas-vouchers's People

Contributors

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