2025-12-20 22:18:14 +01:00
|
|
|
"""Profile routes for user contact details."""
|
2025-12-21 21:54:26 +01:00
|
|
|
|
2025-12-25 18:42:46 +01:00
|
|
|
from fastapi import APIRouter, Depends
|
2025-12-20 22:18:14 +01:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
2025-12-21 23:50:06 +01:00
|
|
|
from auth import require_permission
|
2025-12-20 22:18:14 +01:00
|
|
|
from database import get_db
|
2025-12-21 23:50:06 +01:00
|
|
|
from models import Permission, User
|
2025-12-20 22:18:14 +01:00
|
|
|
from schemas import ProfileResponse, ProfileUpdate
|
2025-12-25 18:42:46 +01:00
|
|
|
from services.profile import ProfileService
|
2025-12-20 22:18:14 +01:00
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api/profile", tags=["profile"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("", response_model=ProfileResponse)
|
|
|
|
|
async def get_profile(
|
2025-12-21 23:50:06 +01:00
|
|
|
current_user: User = Depends(require_permission(Permission.MANAGE_OWN_PROFILE)),
|
2025-12-20 22:18:14 +01:00
|
|
|
db: AsyncSession = Depends(get_db),
|
|
|
|
|
) -> ProfileResponse:
|
|
|
|
|
"""Get the current user's profile (contact details and godfather)."""
|
2025-12-25 18:42:46 +01:00
|
|
|
service = ProfileService(db)
|
|
|
|
|
return await service.get_profile(current_user)
|
2025-12-20 22:18:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.put("", response_model=ProfileResponse)
|
|
|
|
|
async def update_profile(
|
|
|
|
|
data: ProfileUpdate,
|
|
|
|
|
db: AsyncSession = Depends(get_db),
|
2025-12-21 23:50:06 +01:00
|
|
|
current_user: User = Depends(require_permission(Permission.MANAGE_OWN_PROFILE)),
|
2025-12-20 22:18:14 +01:00
|
|
|
) -> ProfileResponse:
|
|
|
|
|
"""Update the current user's profile (contact details)."""
|
2025-12-25 18:42:46 +01:00
|
|
|
service = ProfileService(db)
|
|
|
|
|
return await service.update_profile(current_user, data)
|