Fix SQLModel select syntax in dependencies and songs API

This commit is contained in:
Mikan
2026-11-22 08:46:56 +04:00
parent 4e75111496
commit 1c783f35b3
2 changed files with 8 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from sqlmodel import Session
from sqlmodel import Session, select
from app.db.session import get_session
from app.models.music import User, UserRole
from app.core.security import decode_access_token
@@ -20,7 +20,7 @@ async def get_current_user(
)
username = payload.get("sub")
user = session.exec(User.select().where(User.username == username)).first()
user = session.exec(select(User).where(User.username == username)).first()
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user

View File

@@ -2,7 +2,7 @@ import os
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Form
from fastapi.responses import FileResponse
from sqlmodel import Session
from sqlmodel import Session, select
from app.db.session import get_session
from app.models.music import Song, UserRole, SavedSong
from app.api.dependencies import RoleChecker, get_current_user
@@ -42,7 +42,7 @@ async def upload_song(
@router.get("/{song_id}/stream")
async def stream_song(song_id: int, session: Session = Depends(get_session)):
song = session.exec(Song.select().where(Song.id == song_id)).first()
song = session.exec(select(Song).where(Song.id == song_id)).first()
if not song:
raise HTTPException(status_code=404, detail="Song not found")
@@ -53,9 +53,9 @@ async def list_songs(
session: Session = Depends(get_session),
user=Depends(get_current_user)
):
songs = session.exec(Song.select()).all()
songs = session.exec(select(Song)).all()
# Get IDs of songs saved by current user
saved_songs = session.exec(SavedSong.select().where(SavedSong.user_id == user.id)).all()
saved_songs = session.exec(select(SavedSong).where(SavedSong.user_id == user.id)).all()
saved_set = {s.song_id for s in saved_songs}
results = []
@@ -76,7 +76,7 @@ async def save_song(
user=Depends(get_current_user),
session: Session = Depends(get_session)
):
existing = session.exec(SavedSong.select().where(
existing = session.exec(select(SavedSong).where(
SavedSong.user_id == user.id,
SavedSong.song_id == song_id
)).first()
@@ -95,7 +95,7 @@ async def unsave_song(
user=Depends(get_current_user),
session: Session = Depends(get_session)
):
existing = session.exec(SavedSong.select().where(
existing = session.exec(select(SavedSong).where(
SavedSong.user_id == user.id,
SavedSong.song_id == song_id
)).first()