Created Queries and Execute endpoint
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
# dependencies.py
|
||||
from fastapi import Depends, HTTPException, status, Security
|
||||
|
||||
from fastapi.security import APIKeyHeader
|
||||
@@ -6,10 +5,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.future import select
|
||||
from data.db import SessionLocal
|
||||
from data.models import User, UserRole
|
||||
from pydantic import BaseModel
|
||||
|
||||
# class UserInDB(User):
|
||||
# hashed_password: str
|
||||
|
||||
async def get_db():
|
||||
async with SessionLocal() as session:
|
||||
@@ -18,7 +13,7 @@ async def get_db():
|
||||
API_KEY_NAME = "Authorization"
|
||||
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
||||
|
||||
async def get_current_user(db: AsyncSession = Depends(get_db), api_key:str = Security(api_key_header)):
|
||||
async def get_current_user(db: AsyncSession = Depends(get_db), api_key:str = Security(api_key_header)) -> User:
|
||||
if api_key_header is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail="API key missing"
|
||||
@@ -34,7 +29,7 @@ async def get_current_user(db: AsyncSession = Depends(get_db), api_key:str = Sec
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
|
||||
return user
|
||||
|
||||
async def get_admin_user(current_user: User = Depends(get_current_user)):
|
||||
async def get_admin_user(current_user: User = Depends(get_current_user)) -> User:
|
||||
if current_user.role != UserRole.admin:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Not enough permissions")
|
||||
return current_user
|
||||
|
||||
Reference in New Issue
Block a user