/roster-srcv

basic service to operate on rosters

Primary LanguageGo

Roster change

Usage

A Makefile are provided which should be used to test, build and run the service. The service is started in a docker container. The configuration resides in the docker-compose file. The Dockerfile used to build images is located in the project root.

Build

Builds will be placed in the /bin directory. Binaries use the latest git commit hash or tag as a version.

Run

The service is intended to be ran in a docker container.

make run

API

The provided API methods are HTTP/1.1 compliant according to RFC2616 and RFC5789.

PATCH endpoints expect request payloads to be formatted according to the JSON Merge Patch definition of RFC7396.

Add a player

The application supports adding of new players. The endpoint expects a POST request with a JSON payload containing the player data. New players will be benched by default. If supplied, the player-id will be ignored. Instead, it is generated by the datastore and returned with the complete player representation in JSON format on success.

POST /players/add

curl -X POST http://127.0.0.1:8080/players/add \
    -H "Content-Type: application/json" \
    -d '{"roster_id":382574876546039808,"first_name":"foo","last_name":"bar","alias":"foobar"}'

Add a player to the roster

To add a player to a roster, a PATCH request must be used since a partial update is performed to an existing resource. The request payload needs to contain the new roster-id. A JSON representation of the updated player is returned. An error is returned it the roster does not exist or the roster will be in an invalid state (more or less than 5 active players). When adding a player to a new roster, the player is benched by default to not corrupt the roster's state.

PATCH /players/update

curl -i -X PATCH http://127.0.0.1:8080/players/update \
    -H "Content-Type: application/json" \
    -d '{"player_id":444322878230495243,"roster_id":382574876546039808}'

Move a player to the active roster

When activating a player, another active player needs to be benched to keep the roster in a valid state. The endpoint expects a PATCH request with a JSON payload containing two player ids of which one must be active and one must be benched. Both players must be in the same roster. If successful, a JSON representation of the updated players is returned.

PATCH /players/change

curl -i -X PATCH http://127.0.0.1:8080/players/change \
    -H "Content-Type: application/json" \
    -d '{"active":{"player_id":444322878230495243},"benched":{"player_id":184315303323238400}}'

Fetch the entire roster

A JSON representation or the entire roster can be retrieved via a GET request. The roster is identified by the provided id in the URL path.

GET /roster/:id

curl -X GET http://127.0.0.1:8080/roster/382574876546039808

Fetch benched/active players

A JSON representation of the benched and active players of a roster can be retrieved via a GET request.

GET /roster/:id/:status

curl -X GET http://127.0.0.1:8080/roster/382574876546039808/benched

Tests

There are several targets available to run tests.

make test # runs tests
make test-cover # creates a coverage profile
make test-race # tests service for race conditions

Lint

There is a lint target which runs golangci-lint in a docker container.

make lint

Code changes

After making changes to the code, it is required to rebuild the image(s):

docker-compose up --detach --build <service_name>