From 905bb4e28aa9567dbb72fac63c77fb24aa7d9f02 Mon Sep 17 00:00:00 2001 From: Harikrishna R Date: Sat, 31 Aug 2024 11:47:19 +0530 Subject: [PATCH] routes added --- server/routes/song.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/routes/song.py b/server/routes/song.py index e991685..678669e 100644 --- a/server/routes/song.py +++ b/server/routes/song.py @@ -11,7 +11,6 @@ from models.song import Song from database import get_db from pydantics_schema.favourite_song import FavouriteSong - router = APIRouter() @router.post('/upload',status_code=201) @@ -76,4 +75,10 @@ def favourite_song(song: FavouriteSong, db: Session = Depends(get_db), auth_dict def list_fav_songs(db: Session = Depends(get_db), auth_dict = Depends(auth_middleware)): user_id = auth_dict['uid'] fav_songs = db.query(Favourite).filter(Favourite.user_id == user_id).options(joinedload(Favourite.song), ).all() - return fav_songs \ No newline at end of file + return fav_songs + + +@router.get('/search/',status_code=200) +def search_songs(query: str, db: Session = Depends(get_db),auth_dict = Depends(auth_middleware)): + songs = db.query(Song).filter(Song.song_name.ilike(f'%{query}%')).limit(10).all() + return songs \ No newline at end of file