Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions routes/song_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down