Foosball is a game between two users, particularly liked in startups.
Each user has a team of 11 players (named p1 - p2 - p3 ... from goalkeeper to forwards).
+----------+
| |
+------------------------------------------+
| |
| p1 | # goalkeeper
| |
| |
| p2 p3 | # defenders
| |
| |
| p4 p5 p6 p7 p8 | # midfielders
| |
| |
| p9 p10 p11 | # forwards
| |
+------------------------------------------+
Each of the players can score goals, the scoring depends on:
- which player scored
- whether the goal was a "gamelle" or not The exact rules are specified in the "Rules" section. This API stores all tournament's results:
- a user can have multiple opponents
- for each couple of users, there will be at most one current score
Provide an API that exposes a POST route to store a new tournament goal and returns the current score between these two users. As a simplification, it is recommended not to use an external database.
- POST /goal:
- the user who scored (represented by his ID), ex. user1
- his opponent (represented by his ID), ex. user2
- the field position of a scorer (ex. "p3")
- whether the goal is a "gamelle" or not (true for a gamelle)
Expose a GET route to know a user's set balance in total, against all users.
The sets must be finished to be counted.
GET /balance?user_id=<user_id>
Returns: {"won": 5, "lost": 3}
This project has been developed using GO language and is using serverless Lambda architecture.
It has been deployed online on AWS resources (RDS database, Lambda functions and API Gateway) and can be tested on this architecture. It can also be installed and tested locally (in this case, AWS resources are emulated).
Online architecture is available at https://api.lbc-foosball.theo.do.
To test goal submission route, use following cURL command (adapt body content to your expectations):
curl -X POST \
https://api.lbc-foosball.theo.do/goal \
-d '{
"scorer": "user1",
"opponent": "user2",
"player": "p1",
"gamelle": false
}'
To test user set balance route, use following cURL command (adapt query parameter to your expectations):
curl -X GET \
'https://api.lbc-foosball.theo.do/balance?user_id=user1'
To make this project work on your machine, you need to install following prerequisites:
- GO version 1.12.6 or above
- Docker
- Docker Compose
- AWS CLI to manage AWS resources
- AWS SAM to emulate AWS resources locally
Once finished, just go to main folder and launch following command:
make install
It will install the complete project and its prerequisites.
For more available commands, just launch:
make help
Once installed, you can launch local API by launching following command:
make start
Local API is available at http://localhost:3000.
To test goal submission route, use following cURL command (adapt body content to your expectations):
curl -X POST \
http://localhost:3000/goal \
-d '{
"scorer": "user1",
"opponent": "user2",
"player": "p1",
"gamelle": false
}'
To test user set balance route, use following cURL command (adapt query parameter to your expectations):
curl -X GET \
'http://localhost:3000/balance?user_id=user1'
To launch GO tests with coverage, just launch following command:
make test