Skip to content

langrenn-sprint/competition-format-service

Repository files navigation

competition-format-service

Backend service to administrate competition formats.

Supported competition formats:

in this version:

  • Interval Start competition,
  • Individual sprint competition without a qualification round.

In future versions:

  • Mass start competition,
  • Skiathlon competition,
  • Pursuit,
  • Individual sprint competition with a qualification round,
  • Team sprint competition, and
  • Relay competitions.

Usage example

% curl -H "Content-Type: application/json" \
  -X POST \
  --data '{"username":"admin","password":"password"}' \
  http://localhost:8081/login
% export ACCESS="" #token from response
% curl -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS" \
  -X POST \
  --data @tests/files/competition_format_individual_sprint.json \
  http://localhost:8080/competition-formats
% curl http://localhost:8080/competition-formats # list all competition formats
% curl "http://localhost:8080/competition-formats?name=Individual%20Sprint" # search competition format by name
% curl http://localhost:8080/competition-formats/<the_id> # get competition format by id
% % curl \
  -H "Authorization: Bearer $ACCESS" \
  -X DELETE \
  http://localhost:8080/competition-formats/<the_id>

Look to the openAPI specification for the details.

Running the API locally

Start the server locally:

% uv run --env-file=.env fastapi dev

Running the API in a wsgi-server (gunicorn)

% uv run --env-file=.env uvicorn app:api --host 0.0.0.0 --port 8000 --reload --log-config=logging.yaml

Running the wsgi-server in Docker

To build and run the api in a Docker container:

% docker build -t ghcr.io/langrenn-sprint/competition-format-service:latest .
% docker run --env-file .env -p 8080:8080 -d ghcr.io/langrenn-sprint/competition-format-service:latest

The easier way would be with docker compose:

% docker compose up --build

Running tests

We use pytest for contract testing.

To run linters, checkers and tests:

% uv run poe release

To run specific test:

% uv run poe integration-test --no-cov -- tests/integration/test_competition_formats.py::test_create_competition_format_interval_start

To run tests with logging, do:

% uv run poe integration-test  --log-cli-level=DEBUG

Environment variables

An example .env file for local development:

JWT_SECRET=secret
JWT_EXP_DELTA_SECONDS=3600
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
USERS_HOST_SERVER=localhost
USERS_HOST_PORT=8081
DB_USER=competition-format-service
DB_PASSWORD=password
LOGGING_LEVEL=DEBUG

Clean pycache files

% py3clean .

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors