web sttarting
This commit is contained in:
@@ -3,13 +3,11 @@ from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
import uuid
|
||||
|
||||
from bd import Settings
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from bd import make_engine
|
||||
|
||||
from bd.tables.question import Question
|
||||
from bd.tables.poll import Poll
|
||||
from route.auth_utils import get_current_user
|
||||
from route.auth_utils import require_admin_key
|
||||
|
||||
router = APIRouter(tags=["questions"], prefix="/questions")
|
||||
|
||||
@@ -28,13 +26,12 @@ class QuestionUpdate(BaseModel):
|
||||
|
||||
|
||||
def get_session():
|
||||
settings = Settings()
|
||||
engine = create_engine(settings.DATABASE_URL_syncpg, future=True)
|
||||
return sessionmaker(bind=engine, future=True)
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
return sessionmaker(bind=make_engine(), future=True)
|
||||
|
||||
|
||||
@router.post("/", status_code=201)
|
||||
def create_question(payload: QuestionCreate, _: object = Depends(get_current_user)):
|
||||
@router.post("/", status_code=201, dependencies=[Depends(require_admin_key)])
|
||||
def create_question(payload: QuestionCreate):
|
||||
Session = get_session()
|
||||
try:
|
||||
pid = uuid.UUID(payload.poll_id)
|
||||
@@ -51,8 +48,8 @@ def create_question(payload: QuestionCreate, _: object = Depends(get_current_use
|
||||
return {"id": str(q.id)}
|
||||
|
||||
|
||||
@router.put("/{question_id}")
|
||||
def update_question(question_id: str, payload: QuestionUpdate, _: object = Depends(get_current_user)):
|
||||
@router.put("/{question_id}", dependencies=[Depends(require_admin_key)])
|
||||
def update_question(question_id: str, payload: QuestionUpdate):
|
||||
Session = get_session()
|
||||
try:
|
||||
qid = uuid.UUID(question_id)
|
||||
@@ -74,8 +71,8 @@ def update_question(question_id: str, payload: QuestionUpdate, _: object = Depen
|
||||
return {"id": str(q.id)}
|
||||
|
||||
|
||||
@router.delete("/{question_id}", status_code=204)
|
||||
def delete_question(question_id: str, _: object = Depends(get_current_user)):
|
||||
@router.delete("/{question_id}", status_code=204, dependencies=[Depends(require_admin_key)])
|
||||
def delete_question(question_id: str):
|
||||
Session = get_session()
|
||||
try:
|
||||
qid = uuid.UUID(question_id)
|
||||
|
||||
Reference in New Issue
Block a user