Nuevos cambios en el backend

This commit is contained in:
Mireya Cueto Garrido
2026-05-19 10:21:34 +02:00
parent 02da44fb30
commit ba2507918b
20 changed files with 494 additions and 55 deletions
+21
View File
@@ -0,0 +1,21 @@
from typing import Annotated
from fastapi import Depends
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from sqlalchemy.orm import Session
from app.core.errors import UnauthorizedError
from app.db.session import get_db
from app.models.user import User
from app.services.auth_service import AuthService, get_auth_service
bearer_scheme = HTTPBearer(auto_error=False)
def get_current_user(
credentials: Annotated[HTTPAuthorizationCredentials | None, Depends(bearer_scheme)],
auth_service: Annotated[AuthService, Depends(get_auth_service)],
) -> User:
if credentials is None or credentials.scheme.lower() != "bearer":
raise UnauthorizedError("Missing or invalid authorization token")
return auth_service.get_user_by_id(auth_service.decode_user_id(credentials.credentials))
+4
View File
@@ -18,6 +18,10 @@ class Settings(BaseSettings):
llm_base_url: str = "https://api.openai.com/v1"
llm_model: str = "gpt-4o-mini"
llm_timeout_seconds: int = Field(default=60, ge=5)
jwt_secret_key: str = Field(min_length=32)
jwt_algorithm: str = "HS256"
jwt_expire_minutes: int = Field(default=60 * 24, ge=5)
google_client_id: str | None = None
model_config = SettingsConfigDict(
env_file=".env",
+15
View File
@@ -26,6 +26,21 @@ class ParseError(AppError):
super().__init__(message=message, status_code=422, code="parse_error")
class ConflictError(AppError):
def __init__(self, message: str = "Resource already exists") -> None:
super().__init__(message=message, status_code=409, code="conflict")
class ForbiddenError(AppError):
def __init__(self, message: str = "Access denied") -> None:
super().__init__(message=message, status_code=403, code="forbidden")
class UnauthorizedError(AppError):
def __init__(self, message: str = "Unauthorized") -> None:
super().__init__(message=message, status_code=401, code="unauthorized")
def error_payload(code: str, message: str, details: object | None = None) -> dict[str, object]:
payload: dict[str, object] = {"error": {"code": code, "message": message}}
if details is not None: