MVP frontend+backend
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
"""HTTP routes for auth: register, login, logout, me, refresh."""
|
||||
|
||||
from fastapi import APIRouter, Cookie, HTTPException, Response, status
|
||||
from pydantic import BaseModel
|
||||
from starlette.requests import Request
|
||||
|
||||
from app.config import settings
|
||||
from app.dependencies import AuthServiceDep, CurrentUserDep
|
||||
from app.main import limiter
|
||||
from app.dependencies import AuthServiceDep, ChildRepositoryDep, CurrentUserDep, PersonalDataRepositoryDep
|
||||
from app.rate_limit import limiter
|
||||
from app.models.auth import LoginRequest, RegisterRequest, TokenResponse, UserMeResponse
|
||||
from app.utils.errors import AuthError, ConflictError, UnauthorizedError
|
||||
|
||||
@@ -83,6 +84,41 @@ async def me(current_user: CurrentUserDep) -> UserMeResponse:
|
||||
)
|
||||
|
||||
|
||||
class _ChildContext(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
birth_date: str
|
||||
|
||||
|
||||
class _UserContext(BaseModel):
|
||||
personal_data_uuid: str
|
||||
workspace_id: str
|
||||
parent_name: str
|
||||
children: list[_ChildContext]
|
||||
|
||||
|
||||
@router.get("/context", response_model=_UserContext)
|
||||
async def get_context(
|
||||
current_user: CurrentUserDep,
|
||||
pd_repo: PersonalDataRepositoryDep,
|
||||
child_repo: ChildRepositoryDep,
|
||||
) -> _UserContext:
|
||||
"""Return workspace + children for the current user. Used by the dev harness."""
|
||||
pd = await pd_repo.get_by_id(current_user.personal_data_uuid)
|
||||
if pd is None:
|
||||
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, "No parent profile found")
|
||||
children = await child_repo.list_by_workspace(pd.workspace_id)
|
||||
return _UserContext(
|
||||
personal_data_uuid=str(pd.uuid),
|
||||
workspace_id=str(pd.workspace_id),
|
||||
parent_name=pd.name,
|
||||
children=[
|
||||
_ChildContext(id=str(c.id), name=c.name, birth_date=str(c.birth_date))
|
||||
for c in children
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def _set_refresh_cookie(response: Response, token: str) -> None:
|
||||
response.set_cookie(
|
||||
key=_REFRESH_COOKIE,
|
||||
|
||||
Reference in New Issue
Block a user