feat: перенос структуры приложения из первой лабы

This commit is contained in:
Ильяс
2026-10-22 22:45:34 +03:00
parent 65003b6119
commit 5893d051c1
19 changed files with 1220 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from __future__ import annotations
from uuid import UUID
from fastapi import Header, Request
from app.schemas import UserResponse
from app.storage import UnauthorizedError, storage
async def get_current_user(
request: Request,
x_user_id: str | None = Header(default=None, alias="X-User-Id"),
) -> UserResponse:
if not x_user_id or not x_user_id.strip():
raise UnauthorizedError("Отсутствует заголовок X-User-Id")
# валидация формата UUID
try:
UUID(x_user_id)
except ValueError:
raise UnauthorizedError("Неверный формат заголовка X-User-Id")
# проверка существования пользователя
user = await storage.get_user_by_id(x_user_id)
return user