Skip to content

Instantly share code, notes, and snippets.

@VarunBatraIT
Last active March 6, 2017 10:02
Show Gist options
  • Save VarunBatraIT/61795d6d0e4a7e857e6ca64c2420b12e to your computer and use it in GitHub Desktop.
Save VarunBatraIT/61795d6d0e4a7e857e6ca64c2420b12e to your computer and use it in GitHub Desktop.

Two different domains.

  • Please consider that your backend is running at backendserver.com and angular app is running at frontendserver.com

Three databases

  • information_db will contain a table shops with columns shop_name, db_name & reqeusts like
id shop_name db_name requests
1 Shop A shop_a 0
2 Shop B shop_b 0
  • shop_a will contain products table
  • shop_b will contain products table.

Products Table

  • discount is in percentage. So listed price will become 100, offered price is 90 for apple below.
id category product discount price
1 fruit apple 10 90
2 fruit mango 5 190

REST Api

  • To add a new shop url is "/shop/" which will accept shop name as a post param. It will return shop id, database name and shop name and a new db will be created with an empty products table. Example /shop/ {name:shop B}
id shop_name db_name requests
1 Shop A shop_a 0
2 Shop B shop_b 0
3 Shop B shop_b_1 0
  • To add a new product in shop with id 1, url will be /shop/1/product with post method. To update Product 1, it will be put/patch request at /shop/1/product/1
  • To add a new product in shop with id 2 will be /shop/2/product with post method. To update Product 1, it will be put/patch request at /shop/2/product/1
  • Thus urls are
  • /shop/ post creates a new shop/
  • /shop/1/products Get gets all the products in shop id 1 like below: Note changes in columns. Below output is in HTML table. Depending on header it can be in JSON.
id Category name Product Name Discount in Percentage Offered Price Original Price
1 fruit apple 10 90 100
2 fruit mango 5 190 200
  • /shop/1/product/ Post will create a new product
  • /shop/1/product/1 Delete will delete product 1 in shop 1
  • /shop/2/product/1 Put/Patch will update product. If product doesn't exist, it will return a proper error (resource not found)
  • With each request in a particular shop, requests column in information_db database (shops table) will be incremented.
  • Please create a migration for parent database in sequelize.
  • Difference between patch and put. In patch, missing params will be ignored. In put, missing params will be consider as defaults. For example if discount is missing in put metchod and earlier discount was 20, discount will become 0.
  • Please use Sequelize, Angular 2, Express and axios, From html return of table use PUG.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment