This project exposes a RESTful API for a simple application where football/soccer fans will create fantasy teams and will be able to sell or buy players.
- Summary
- Documentation
- Tech Stack
- Development Setup
- API Documentation
- 1. Register a new user
- 2. Generate Authorization Token
- 3. Get User By Email [Authorization Token Required in headers]
- 4. Get Team By ID [Authorization Token Required in headers]
- 5. Update Team (Name, Country) By ID [Authorization Token Required in headers]
- 6. Get Player By ID [Authorization Token Required in headers]
- 7. Update Player (First Name, Last Name, Country) By ID [Authorization Token Required in headers]
- 8. Add Player to transfer list [Authorization Token Required in headers]
- 9. Get all players on the transfer list [Authorization Token Required in headers]
- 10. Buy player from the transfers list [Authorization Token Required in headers]
- Future Improvements
Written in Go (Golang 1.18) using gin as web framework, Postgres as database.
The application is containerized using docker and code-syncin development env uses docker-sync.
- Use
make build
to build the web server andmake start
to start the server. Server runs onlocalhost:8080
. - Use
make stop
stop the development environment. - Use
make clean
to clean the dev environment by deleting stale containers. - Use
docker volume prune
to clean all volumes in case of local DB failure. [Warning: This will prune all volumes] - Use
make test
runs the tests in a seperate docker container for isolation. [TODO] - Air and docker-sync are used for live reloading during development.
make
git
docker (v20.10.10)
docker-compose (v1.29.2)
docker-sync (0.7.2) [Use `gem install docker-sync -v 0.7.2` for mac]
- Docker-Sync Install: http://docker-sync.io/
- Docker Install: https://docs.docker.com/engine/install/
- Clone repository
git clone https://github.com/nvzard/soccer-manager.git
- Change the directory to the cloned repository
cd soccer-manager
- Make sure all requirements are installed (docker, docker-compose, docker-sync)
docker --version
docker-compose --version
docker-sync --version
- Build image
make build
- Run start command
make start
PS: If make start
fails for the first time use make stop
to stop the containers and do make start
again.
make stop
make test
make clean
GET /healthcheck # ok
POST /api/user # register new user (json parameters: first_name, last_name, email, password)
POST /api/auth # generate Authorization token for the user (json parameters: email, password)
[** Below API Endpoints Require Authorization token in header **]
GET /api/ping # pong
GET /api/user/:email # get user by email
GET /api/team/:id # get team by id
PATCH /api/team/:id # update team by id (json parameters: name, country)
GET /api/player/:id # get player by id
PATCH /api/player/:id # update team by id (json parameters: first_name, last_name, country)
GET /api/transfers/ # get the transfers list
POST /api/transfers/ # add player to transfer list (json parameters: player_id, asking_price)
POST /api/transfers/buy/:player_id # buy a player on the transfers list for the asking_price
POST /api/user
JSONParameter | Type | Description |
---|---|---|
first_name |
string |
FirstName of the user |
last_name |
string |
LastName of the user |
email |
string |
valid email address |
password |
string |
password (len >= 8) |
POST /api/user
{
"first_name": "John",
"last_name": "Lennon",
"email": "[email protected]",
"password": "qwerty65",
}
{
"id": 1,
"email": "[email protected]"
}
POST /api/auth
JSONParameter | Type | Description |
---|---|---|
email |
string |
email of the user |
password |
string |
password of the user |
POST /api/user
{
"email": "[email protected]",
"password": "qwerty65",
}
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJkcmFrZUBnbWFpbC5jb20iLCJ0ZWFtX2lkIjoxLCJleHAiOjE2NTc4Mjc4MTl9"
}
GET /api/user/:email
GET /api/user/[email protected]
{
"id": 1,
"email": "[email protected]",
"first_name": "John",
"last_name": "Lennon",
"team_id": 1
}
GET /api/team/:id
GET /api/team/1
Every newly formed team has 3 goalkeepers(GK), 6 defenders(DEF), 6 midfielders(MID), 5 attackers(ATT)
{
"available_cash": 5000000,
"country": "France",
"id": 1,
"name": "Iron Squids",
"owner_id": 1,
"players": [
{
"id": 1,
"first_name": "Douglas",
"last_name": "Mejia",
"country": "Germany",
"age": 36,
"position": "GK",
"market_value": 1000000,
"team_id": 1
},
.
.
.
{
"id": 20,
"first_name": "Ryland",
"last_name": "Mejia",
"country": "USA",
"age": 23,
"position": "ATT",
"market_value": 1000000,
"team_id": 1
}
],
"team_value": 20000000
}
PATCH /api/team/:id
JSONParameter | Type | Description |
---|---|---|
name |
string |
new team name |
country |
string |
new team country |
PATCH /api/team/1
{
"name": "Leopards"
"country": "China",
}
{
"id": 1,
"available_cash": 5000000,
"country": "China",
"name": "Leopards",
"owner_id": 1,
"players": [
{
"id": 1,
"first_name": "Douglas",
"last_name": "Mejia",
"country": "Germany",
"age": 36,
"position": "GK",
"market_value": 1000000,
"team_id": 1
},
.
.
.
{
"id": 20,
"first_name": "Ryland",
"last_name": "Mejia",
"country": "USA",
"age": 23,
"position": "ATT",
"market_value": 1000000,
"team_id": 1
}
],
"team_value": 20000000
}
GET /api/player/:id
GET /api/player/5
{
"id": 5,
"age": 32,
"country": "Germany",
"first_name": "Nathaniel",
"last_name": "Mejia",
"market_value": 1000000,
"position": "DEF",
"team_id": 1
}
PATCH /api/player/:id
JSONParameter | Type | Description |
---|---|---|
first_name |
string |
new first name |
last_name |
string |
new last name |
country |
string |
new country |
PATCH /api/team/1
{
"first_name": "Saitama",
"last_name": "Senpai",
"country": "Japan",
}
{
"id": 1,
"first_name": "Saitama",
"last_name": "Senpai",
"age": 36,
"country": "Japan",
"market_value": 1000000,
"position": "GK",
"team_id": 1
}
POST /api/transfers
JSONParameter | Type | Description |
---|---|---|
player_id |
string |
id of the player |
asked_price |
string |
asked price for the player |
POST /api/transfers
{
"player_id": 6,
"asked_price": 1050000
}
{
"transfer_id": 8
}
GET /api/transfers
GET /api/transfers
{
"transfer_list": [
{
"id": 1,
"player_id": 6,
"market_value": 1000000,
"asked_price": 1050000,
"player": {
"id": 6,
"first_name": "Grant",
"last_name": "Klein",
"country": "Qatar",
"age": 23,
"position": "DEF",
"market_value": 1000000,
"team_id": 1
}
}
]
}
POST /transfers/buy/:player_id
This transfers the player from selling team to buying team and adjusts the team's bank balance accordingly. A player's market value increases by 10-100% after every transfer.
POST /transfers/buy/6
{
"status": "done"
}
Some of the improvements that can be made but were skipped due to time constraints.
- Add unit tests.
- Add postman collection to test and document the API.
- Add admin roles to have CRUD access for all the users, teams, players and transfers.
- Build a user-interface(UI) for the backend.