feat: initial commit
This commit is contained in:
commit
e8291f4bef
33 changed files with 10300 additions and 0 deletions
8
apps/http/chalice/.chalice/config.json
Normal file
8
apps/http/chalice/.chalice/config.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"version": "2.0",
|
||||
"app_name": "secretsanta",
|
||||
"stages": {
|
||||
"dev": {
|
||||
}
|
||||
}
|
||||
}
|
||||
0
apps/http/chalice/__init__.py
Normal file
0
apps/http/chalice/__init__.py
Normal file
52
apps/http/chalice/app.py
Normal file
52
apps/http/chalice/app.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import anyio
|
||||
from chalice import Chalice
|
||||
|
||||
from secretsanta.domain import Group
|
||||
from secretsanta.repo import S3Repo
|
||||
from secretsanta.service import (
|
||||
GetGroupParticipantsService,
|
||||
CreateGroupService,
|
||||
GetPairService,
|
||||
)
|
||||
from secretsanta.settings import get_config
|
||||
|
||||
config = get_config()
|
||||
app = Chalice(app_name="secretsanta", debug=config.environment == "local")
|
||||
|
||||
repo = S3Repo()
|
||||
|
||||
|
||||
def _participants2url(participants: list[str], group_uuid: str) -> list[str]:
|
||||
return [
|
||||
f"{config.server_url}/api/v1/groups/{group_uuid}/pair/{participant_name}"
|
||||
for participant_name in participants
|
||||
]
|
||||
|
||||
|
||||
@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)
|
||||
participants = anyio.run(service.run, Group(uuid=group_uuid, **body)).participants
|
||||
return _participants2url(participants, group_uuid)
|
||||
|
||||
|
||||
@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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue