|
6 | 6 | from fastapi.security import APIKeyHeader |
7 | 7 | from typing_extensions import Annotated, AsyncGenerator |
8 | 8 |
|
| 9 | +from app.core.db import Database, SessionLocal |
| 10 | +from app.core.logic import Logic |
| 11 | +from app.core.security import Security |
9 | 12 | from app.models.user import User |
10 | 13 |
|
11 | | -from . import Security, db, exps |
12 | 14 |
|
13 | | - |
14 | | -async def get_db() -> AsyncGenerator[db.Database]: |
15 | | - async with db.SessionLocal() as session: |
16 | | - yield db.Database(session) |
| 15 | +async def get_db() -> AsyncGenerator[Database]: |
| 16 | + async with SessionLocal() as session: |
| 17 | + yield Database(session) |
17 | 18 |
|
18 | 19 |
|
19 | 20 | async def get_security() -> Security: |
20 | 21 | return Security() |
21 | 22 |
|
22 | 23 |
|
| 24 | +async def get_logic( |
| 25 | + db: Annotated[Database, Depends(get_db)], |
| 26 | + security: Annotated[Security, Depends(get_security)], |
| 27 | +) -> Logic: |
| 28 | + return Logic(db, security) |
| 29 | + |
| 30 | + |
23 | 31 | async def get_current_user( |
24 | 32 | token: Annotated[str, Depends(APIKeyHeader(name='access-token'))], |
25 | | - security: Annotated[Security, Depends(get_security)], |
26 | | - db: Annotated[db.Database, Depends(get_db)], |
| 33 | + logic: Annotated[Logic, Depends(get_logic)], |
27 | 34 | ) -> User | None: |
28 | | - if payload := security.jwt.decode_token(token): |
29 | | - if not (user := await db.user.retrieve_one(ident=payload.get('id'))): |
30 | | - raise exps.USER_NOT_FOUND |
31 | | - else: |
32 | | - return user |
| 35 | + return await logic.users.retrieve_by_token(token) |
0 commit comments