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:
- has unique id (containing Campaign prefix)
- discount - percentage or flat value
- can be used once or multiple times
- can expire
- campaign id is a prefix for voucher ids
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
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
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
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