Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Backend Software Engineering: Python Please write a web service that accepts HTTP requests and returns responses based on the conditions outlined in the next section.

Backend Software Engineering: Python

Please write a web service that accepts HTTP requests and returns responses based on the conditions outlined in the next

section.

What does it need to do?

Background

Our users have points in their accounts. Users only see a single balance in their accounts. But for reporting purposes we actually track their points per payer/partner. In our system, each transaction record contains: payer (string), points (integer),timestamp (date).

For earning points it is easy to assign a payer, we know which actions earned the points. And thus which partner should be paying for the points.

When a user spends points, they don't know or care which payer the points come from. But, our accounting team does care how the points are spent. There are two rules for determining what points to "spend" first:

We want the oldest points to be spent first (oldest based on transaction timestamp, not the order theyre received)

We want no payer's points to go negative.

We expect your web service to

Provide routes that:

Add transactions for a specific payer and date.

Spend points using the rules above and return a list of { "payer": , "points": } for each call.

Return all payer point balances.

Note:

We are not defining specific requests/responses. Defining these is part of the exercise.

We dont expect you to use any durable data store. Storing transactions in memory is acceptable for the exercise.

Example

Suppose you call your add transaction route with the following sequence of calls:

{ "payer": "DANNON", "points": 1000, "timestamp": "2020-11-02T14:00:00Z" }

{ "payer": "UNILEVER", "points": 200, "timestamp": "2020-10-31T11:00:00Z" }

{ "payer": "DANNON", "points": -200, "timestamp": "2020-10-31T15:00:00Z" }

{ "payer": "MILLER COORS", "points": 10000, "timestamp": "2020-11-01T14:00:00Z" }

{ "payer": "DANNON", "points": 300, "timestamp": "2020-10-31T10:00:00Z" }

Then you call your spend points route with the following request:

{ "points": 5000 }

The expected response from the spend call would be:

[

{ "payer": "DANNON", "points": -100 },

{ "payer": "UNILEVER", "points": -200 },

{ "payer": "MILLER COORS", "points": -4,700 }

]

A subsequent call to the points balance route, after the spend, should returns the following results:

{

"DANNON": 1000,

"UNILEVER": 0,

"MILLER COORS": 5300

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

What are some of the possible scenes from our future?

Answered: 1 week ago

Question

1. What are your creative strengths?

Answered: 1 week ago