restructure session management
This commit is contained in:
27
app/routers/session.py
Normal file
27
app/routers/session.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Annotated
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import app.models as models
|
||||
from app.database import get_db
|
||||
from app.schemas import Song
|
||||
import app.crud as crud
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/session",
|
||||
# dependencies=[Security(get_current_user, scopes=["public"])],
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
|
||||
@router.put("/{session_id}")
|
||||
async def activate_session(session_id: str = "", db: Annotated[Session, Depends(get_db)] = None):
|
||||
crud.activate_session(db, session_id)
|
||||
|
||||
@router.delete("/{session_id}")
|
||||
async def deactivate_session(session_id: str = "", db: Annotated[Session, Depends(get_db)] = None):
|
||||
crud.deactivate_session(db, session_id)
|
||||
|
||||
#@router.get("/{session_id}")
|
||||
#async def get_session(session_id: str = "", db: Annotated[Session, Depends(get_db)] = None):
|
||||
# return "get " + session_id
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy.orm import Session
|
||||
import app.models as models
|
||||
from app.database import get_db
|
||||
from app.schemas import Song
|
||||
from app.crud import get_songs_and_vote_for_user, create_or_update_vote, get_all_songs_and_votes
|
||||
from app.crud import get_songs_and_vote_for_session, create_or_update_vote, get_all_songs_and_votes
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/songs",
|
||||
@@ -15,13 +15,13 @@ router = APIRouter(
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def get_songs(user_id: str = "", db: Annotated[Session, Depends(get_db)] = None) -> list[Song]:
|
||||
return [Song(**s.__dict__, vote=v) for s, v in get_songs_and_vote_for_user(db, user_id)]
|
||||
async def get_songs(session_id: str = "", db: Annotated[Session, Depends(get_db)] = None) -> list[Song]:
|
||||
return [Song(**s.__dict__, vote=v) for s, v in get_songs_and_vote_for_session(db, session_id)]
|
||||
|
||||
|
||||
@router.post("/{song_id}/vote")
|
||||
async def vote(song_id: str, user_id: str, vote: int, db: Annotated[Session, Depends(get_db)]):
|
||||
create_or_update_vote(db, song_id, user_id, vote)
|
||||
async def vote(song_id: str, session_id: str, vote: int, db: Annotated[Session, Depends(get_db)]):
|
||||
create_or_update_vote(db, song_id, session_id, vote)
|
||||
|
||||
|
||||
@router.get("/evaluation")
|
||||
|
||||
Reference in New Issue
Block a user