generated _collections class

This commit is contained in:
bdrtr 2025-05-07 20:15:51 +03:00
parent 842c127817
commit 938f950646
6 changed files with 132 additions and 13 deletions

View file

@ -1,5 +1,7 @@
from .models import UserProfile
from .models import UserProfileBase, UserProfileID, UserProfilePrivate, UserProfilePublic, all_users, is_user_exsist
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from ..config import get_session_db
from typing import Annotated
from ..auth.models import get_current_active_user
@ -10,9 +12,37 @@ router = APIRouter(
dependencies=[],
)
@router.get('/profile', response_model=UserProfile)
async def get_user_profile(
current_user: Annotated[UserProfile, Depends(get_current_active_user)]
) -> UserProfile:
@router.get('/all_profiles')
async def get_user_profile(session: Annotated[Session, Depends(get_session_db)]) -> list[UserProfilePublic]:
return current_user
return all_users(session=session)
@router.get('/profile/{username}')
async def get_user_profile_by_username(
username: str,
session: Annotated[Session, Depends(get_session_db)],
) -> UserProfilePublic | dict:
user : UserProfilePublic = is_user_exsist(username, session)
if user is None:
return {"error": "User not found"}
return user
@router.get('/profile/me')
async def get_user_profile_me(
current_user: Annotated[UserProfilePrivate, Depends(get_current_active_user)] #dependtek kaynaklı UserPublic doner
) -> UserProfilePrivate:
return current_user
@router.post('/create')
async def create_user_profile(
user : Annotated[UserProfileID, Depends(get_current_active_user)],
session: Annotated[Session, Depends(get_session_db)],
) -> UserProfileBase:
return user