web sttarting
This commit is contained in:
@@ -3,9 +3,7 @@ from pydantic import BaseModel
|
||||
from typing import List, 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.poll import Poll
|
||||
from bd.tables.question import Question
|
||||
@@ -26,9 +24,8 @@ class ResponseIn(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("/{poll_id}/responses", status_code=201)
|
||||
@@ -71,6 +68,17 @@ def submit_response(poll_id: str, payload: ResponseIn):
|
||||
return {"id": str(resp.id)}
|
||||
|
||||
|
||||
@router.get("/responses/")
|
||||
def list_all_responses():
|
||||
Session = get_session()
|
||||
with Session() as session:
|
||||
rows = session.query(Response).all()
|
||||
return [
|
||||
{"id": str(r.id), "poll_id": str(r.poll_id), "user_id": str(r.user_id) if r.user_id else None, "submitted_at": r.submitted_at.isoformat()}
|
||||
for r in rows
|
||||
]
|
||||
|
||||
|
||||
@router.get("/{poll_id}/responses")
|
||||
def list_responses(poll_id: str):
|
||||
Session = get_session()
|
||||
|
||||
Reference in New Issue
Block a user