Giter VIP home page Giter VIP logo

fetch's Introduction

fetch

fetch awards assignment

Two steps to run the app:

  1. install nodejs 16.15.0 https://nodejs.org/download/release/v16.15.0/
  2. go to the fetch folder and run cmd: npm start

Now the app is started on http://localhost:3000 You can use postman to call it There are four endpoints. The purposes of them are as their names suggest.

  1. http://localhost:3000/v1/balances/all This is a httpget endpoint. You don't need to pass any parameter to use it.

  2. http://localhost:3000/v1/balances/consume This is a httppost endpoint. To use it, you need to pass a JSON object in the body like this: { "points": 200 }

  3. http://localhost:3000/v1/balances/addTransaction This is a httppost endpoint. To use it, you need to pass a JSON object in the body like this: { "payer": "DANNON", "points": 1000, "timestamp": "2022-11-03T14:00:00Z" }

  4. http://localhost:3000/v1/balances/addTransactions This is a httppost endpoint. To use it, you need to pass a JSON object in the body like this: [ { "payer": "DANNON", "points": 300, "timestamp": "2022-10-31T10:00:00Z" }, { "payer": "UNILEVER", "points": 200, "timestamp": "2022-10-31T11:00:00Z" }, { "payer": "DANNON", "points": -200, "timestamp": "2022-10-31T15:00:00Z" }, { "payer": "MILLER COORS", "points": 10000, "timestamp": "2022-11-01T14:00:00Z" }, { "payer": "DANNON", "points": 1000, "timestamp": "2022-11-02T14:00:00Z" } ]

More implementation details: Assumption: It's assumed that the points transaction for each payer happens in an chronological order. The cursor: the cursor of each payer's balance summary points to the pointbalance that's currently in the treeset. The pointbalance before the cursor is zero. Error handling:

  1. The total variable in mymap is used to check if the points to be spent is valid.
  2. If there's a list of add transactions, the transactions will be executed one by one. The failure of one transaction will not stop the executing of other transactions. For example, if the addTransactions endpoints are called with this input: [ {"payer":"DANNON","points":300,"timestamp":"2022-10-31T10:00:00Z"}, {"payer":"UNILEVER","points":200,"timestamp":"2022-10-31T11:00:00Z"}, {"payer":"DANNON","points":-2000,"timestamp":"2022-10-31T15:00:00Z"}, {"payer":"MILLER COORS","points":10000,"timestamp":"2022-11-01T14:00:00Z"}, {"payer":"DANNON","points":1000,"timestamp":"2022-11-02T14:00:00Z"} ] The third transaction will fail, other transaction will succeed. A total of 11500 points will be added. The result of each transaction will be logged.
  3. Pros and Cons: Pros: As nodejs is single threaded, this app can handle concurrency, we don't need to worry about data race. Cons: Nodejs is good to be used for servers and building event-driven architectures, but it's not good to do calculations. To scale the app, we need to distribute the calculation to other servers.

fetch's People

Watchers

 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.