feat: initial commit
This commit is contained in:
commit
e8291f4bef
33 changed files with 10300 additions and 0 deletions
43
apps/http/sls/app.py
Normal file
43
apps/http/sls/app.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import json
|
||||
|
||||
import anyio
|
||||
|
||||
from secretsanta.domain import Group
|
||||
from secretsanta.repo import S3Repo
|
||||
from secretsanta.service import (
|
||||
GetGroupParticipantsService,
|
||||
GetPairService,
|
||||
CreateGroupService,
|
||||
)
|
||||
from secretsanta.settings import get_config
|
||||
|
||||
config = get_config()
|
||||
repo = S3Repo()
|
||||
|
||||
|
||||
def get_participants(event, _):
|
||||
group_uuid = event["pathParameters"]["group_uuid"]
|
||||
service = GetGroupParticipantsService(repo)
|
||||
participants = anyio.run(service.run, group_uuid)
|
||||
|
||||
return {"statusCode": 200, "body": json.dumps(participants)}
|
||||
|
||||
|
||||
def get_pair(event, _):
|
||||
group_uuid = event["pathParameters"]["group_uuid"]
|
||||
participant = event["pathParameters"]["participant"]
|
||||
query_params = event["queryStringParameters"] or {}
|
||||
response_type = query_params.get("type", "plain")
|
||||
service = GetPairService(repo)
|
||||
pair = anyio.run(service.run, group_uuid, participant)
|
||||
if response_type == "json":
|
||||
return {"statusCode": 200, "body": json.dumps({"pair": pair})}
|
||||
return {"statusCode": 200, "body": pair, "headers": {"Content-Type": "text/plain"}}
|
||||
|
||||
|
||||
def create_group(event, _):
|
||||
group_uuid = event["pathParameters"]["group_uuid"]
|
||||
body = json.loads(event["body"])
|
||||
service = CreateGroupService(repo)
|
||||
participants = anyio.run(service.run, Group(uuid=group_uuid, **body))
|
||||
return {"statusCode": 200, "body": json.dumps(participants)}
|
||||
Loading…
Add table
Add a link
Reference in a new issue