Skip to content
Merged
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.
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="This song already exists")
# Allow for partial updates (kinda). We handle melody separately since we want to allow for None
for var, value in vars(song_data).items():
if value is not None:
Expand Down
Loading