diff --git a/routes/song_router.py b/routes/song_router.py index 87c730f..54a0870 100644 --- a/routes/song_router.py +++ b/routes/song_router.py @@ -60,6 +60,10 @@ def update_song(song_id: int, song_data: SongCreate, db: DB_dependency): if song is None: raise HTTPException(status.HTTP_404_NOT_FOUND) + # simply check if the title is being changed to an already existing title, if so, throw an error. Copied from create_song + num_existing = db.query(Song_DB).filter(Song_DB.title == song_data.title).count() + if num_existing > 0: + raise HTTPException(status.HTTP_400_BAD_REQUEST, detail="Ths post already exists") # This does not allow one to "unset" values that could be null but aren't currently for var, value in vars(song_data).items(): setattr(song, var, value) if value else None