web sttarting

This commit is contained in:
2026-03-31 13:25:14 +05:00
parent 9cd6d83428
commit 59b3bcd0f4
30 changed files with 720 additions and 242 deletions

View File

@@ -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.choice import Choice
from bd.tables.question import Question
from route.auth_utils import get_current_user
from route.auth_utils import require_admin_key
router = APIRouter(tags=["choices"], prefix="/choices")
@@ -26,13 +24,12 @@ class ChoiceUpdate(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_choice(payload: ChoiceCreate, _: object = Depends(get_current_user)):
@router.post("/", status_code=201, dependencies=[Depends(require_admin_key)])
def create_choice(payload: ChoiceCreate):
Session = get_session()
try:
qid = uuid.UUID(payload.question_id)
@@ -49,8 +46,8 @@ def create_choice(payload: ChoiceCreate, _: object = Depends(get_current_user)):
return {"id": str(ch.id)}
@router.put("/{choice_id}")
def update_choice(choice_id: str, payload: ChoiceUpdate, _: object = Depends(get_current_user)):
@router.put("/{choice_id}", dependencies=[Depends(require_admin_key)])
def update_choice(choice_id: str, payload: ChoiceUpdate):
Session = get_session()
try:
cid = uuid.UUID(choice_id)
@@ -70,8 +67,8 @@ def update_choice(choice_id: str, payload: ChoiceUpdate, _: object = Depends(get
return {"id": str(ch.id)}
@router.delete("/{choice_id}", status_code=204)
def delete_choice(choice_id: str, _: object = Depends(get_current_user)):
@router.delete("/{choice_id}", status_code=204, dependencies=[Depends(require_admin_key)])
def delete_choice(choice_id: str):
Session = get_session()
try:
cid = uuid.UUID(choice_id)