Spaces:
Running on T4
Running on T4
Download backend/app/modules/settings/controller.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/settings/controller.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/modules/settings/controller.py
-
curl -L -o controller.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/settings/controller.py
1.98 kB
| """N01 to N05: /me/settings, /me/consent, /me/exports.""" | |
| from typing import Annotated | |
| from fastapi import APIRouter, Header, Response | |
| from app.core.dependencies import CurrentAccount, Db | |
| from app.modules.idempotency.service import run_idempotent | |
| from app.modules.settings.schemas import ( | |
| ConsentIn, | |
| ExportEnvelope, | |
| ExportIn, | |
| SettingsEnvelope, | |
| SettingsPatch, | |
| ) | |
| from app.modules.settings.service import SettingsService | |
| router = APIRouter(prefix="/v1", tags=["settings"]) | |
| IdempotencyKey = Annotated[str | None, Header(max_length=128)] | |
| async def read_settings(account: CurrentAccount, db: Db) -> SettingsEnvelope: | |
| return SettingsEnvelope(settings=await SettingsService(db).get(account)) | |
| async def update_settings(body: SettingsPatch, account: CurrentAccount, db: Db) -> SettingsEnvelope: | |
| return SettingsEnvelope(settings=await SettingsService(db).update(account, body)) | |
| async def accept_consent(body: ConsentIn, account: CurrentAccount, db: Db, idempotency_key: IdempotencyKey = None): | |
| service = SettingsService(db) | |
| return await run_idempotent(db, account.id, idempotency_key, body, lambda: service.accept(account, body), | |
| status_code=201) | |
| async def withdraw_consent(account: CurrentAccount, db: Db) -> Response: | |
| await SettingsService(db).withdraw(account) | |
| return Response(status_code=204) | |
| async def request_export(body: ExportIn, account: CurrentAccount, db: Db, idempotency_key: IdempotencyKey = None): | |
| service = SettingsService(db) | |
| return await run_idempotent(db, account.id, idempotency_key, body, lambda: service.request_export(account), | |
| status_code=202) | |