import anyio from chalice import Chalice from secretsanta.domain import Group from secretsanta.repo import S3Repo from secretsanta.service import ( CreateGroupService, GetGroupParticipantsService, GetPairService, ) from secretsanta.settings import get_config config = get_config() app = Chalice(app_name="secretsanta", debug=config.environment == "local") repo = S3Repo() @app.route("/api/v1/groups/{group_uuid}") def get_participants(group_uuid: str): service = GetGroupParticipantsService(repo) return anyio.run(service.run, group_uuid) @app.route("/api/v1/groups/{group_uuid}", methods=["PUT"]) def create_group(group_uuid: str): request = app.current_request body = request.json_body service = CreateGroupService(repo) return anyio.run(service.run, Group(uuid=group_uuid, **body)) @app.route("/api/v1/groups/{group_uuid}/pair/{participant}") def get_pair(group_uuid: str, participant: str): service = GetPairService(repo) pair = anyio.run(service.run, group_uuid, participant) return {"pair": pair} if config.environment == "local": @app.route("/introspect") def introspect(): return app.current_request.to_dict()