go 1.17.6
$ go build
$ ./fetch-exercise
Starting server at port 8080
Add transaction for specific payer, transaction amount, and date
-
URL
/add_transaction
-
Method
POST
-
Request Body
payer
stringpoints
inttimestamp
string
-
Success Response
- Code: 201
Spend points using oldest payer points first and returns which points were spent from which payer
-
URL
/spend_points
-
Method
POST
-
Request Body
points
int
-
Success Response
- Code: 200
- Content:
{ "spent_points": [ { "payer": "DANNON", "points": -100 }, { "payer": "UNILEVER", "points": -200 }, { "payer": "MILLER COORS", "points": -4700 } ] }
-
Error Response
- 400 Bad Request
Get Points returns total payer points
-
URL
/get_points
-
Method
GET
-
Success Response
- Code: 200
- Content:
{ "points": { "DANNON": 1000, "MILLER COORS": 5300, "UNILEVER": 0 } }
curl -H "Content-Type: application/json" -X POST -d '{ "payer": "DANNON", "points": 1000, "timestamp": "2020-11-02T14:00:00Z" }' http://localhost:8080/add_transaction
curl -H "Content-Type: application/json" -X POST -d '{ "payer": "UNILEVER", "points": 200, "timestamp": "2020-10-31T11:00:00Z" }' http://localhost:8080/add_transaction
curl -H "Content-Type: application/json" -X POST -d '{ "payer": "DANNON", "points": -200, "timestamp": "2020-10-31T15:00:00Z" }' http://localhost:8080/add_transaction
curl -H "Content-Type: application/json" -X POST -d '{ "payer": "MILLER COORS", "points": 10000, "timestamp": "2020-11-01T14:00:00Z" }' http://localhost:8080/add_transaction
curl -H "Content-Type: application/json" -X POST -d '{ "payer": "DANNON", "points": 300, "timestamp": "2020-10-31T10:00:00Z" }' http://localhost:8080/add_transaction
{"message":"201 Created"}
{"message":"201 Created"}
{"message":"201 Created"}
{"message":"201 Created"}
{"message":"201 Created"}
curl -H "Content-Type: application/json" -X POST -d '{ "points": 5000 }' http://localhost:8080/spend_points
{
"spent_points": [
{
"payer": "DANNON",
"points": -100
},
{
"payer": "UNILEVER",
"points": -200
},
{
"payer": "MILLER COORS",
"points": -4700
}
]
}
curl -H "Content-Type: application/json" http://localhost:8080/points
{
"points": {
"DANNON": 1000,
"MILLER COORS": 5300,
"UNILEVER": 0
}
}
- Add unit tests
- Handle more validation and errors
- Wrap responses with status codes and messages
- Add persistent storage