Implement Veto Mode

This commit is contained in:
matthias@matsewe.de
2024-05-29 10:33:42 +02:00
parent 010d6fc8d6
commit 0546a88e32
9 changed files with 150 additions and 24 deletions

View File

@@ -8,7 +8,7 @@ from sqlalchemy.orm import Session
from app.database import get_db, engine, Base
from app.routers.user import get_current_user
from app.crud import create_song
from app.crud import create_song, get_setting, set_setting
router = APIRouter(
prefix="/admin",
@@ -66,7 +66,7 @@ def get_spotify_id(url):
@router.post("/load_list")
async def create_upload_file(db: Session = Depends(get_db)):
async def create_upload_file(include_non_singable: bool = False, db: Session = Depends(get_db)):
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
@@ -78,16 +78,24 @@ async def create_upload_file(db: Session = Depends(get_db)):
category_names = list(song_list.iloc[0][8:17])
for i, row in song_list[1:].iterrows():
if (row[17] == "nein") and not include_non_singable:
continue
row = np.array(row)
if not row[2]: # no title
continue
yt_id = get_youtube_id(row[3])
spfy_id = get_spotify_id(row[3])
categories = {n: v for n, v in zip(
category_names, row[8:17] != None)}
if (not np.any(list(categories.values()))) and (row[5] != "ja"):
continue
if (not np.any(list(categories.values()))):
main_category = None
else:
main_category = category_names[get_main_category(row[8:17])]
create_song(db,
og_artist=row[0],
@@ -102,6 +110,18 @@ async def create_upload_file(db: Session = Depends(get_db)):
is_aca=row[6] == "ja",
arng_url=row[7],
categories=categories,
main_category=category_names[get_main_category(row[8:17])],
singable=row[17] != "nein"
main_category=main_category,
singable=row[17] != "nein",
comment=row[18]
)
@router.post("/toggle_veto_mode")
async def toggle_veto_mode(db: Session = Depends(get_db)) -> bool:
veto_setting = get_setting(db, "veto_mode")
if veto_setting:
set_setting(db, "veto_mode", False)
return False
else:
set_setting(db, "veto_mode", True)
return True

View File

@@ -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_session, 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, create_or_update_comment
router = APIRouter(
prefix="/songs",
@@ -16,13 +16,17 @@ router = APIRouter(
@router.get("/")
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)]
return [Song(**s.__dict__, vote=v, vote_comment=c) for s, v, c in get_songs_and_vote_for_session(db, session_id)]
@router.post("/{song_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.post("/{song_id}/comment")
async def comment(song_id: str, session_id: str, comment: str, db: Annotated[Session, Depends(get_db)]):
create_or_update_comment(db, song_id, session_id, comment)
#create_or_update_vote(db, song_id, session_id, vote)
@router.get("/evaluation")
async def get_evaluation(db: Annotated[Session, Depends(get_db)] = None) -> dict[int, dict[int, int]]: