backend/items/router.py

48 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
router = APIRouter(
prefix="/items",
tags=["items"],
responses={404: {"description": "Not found"}},
dependencies=[],
)
@router.get('/all_profiles')
async def get_user_profile(session: Annotated[Session, Depends(get_session_db)]) -> list[UserProfilePublic]:
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