mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-20 15:20:39 -07:00
Fix #134: Add validation for duplicate profile names
- Add validation in create_profile() to check for existing names before insert - Add validation in update_profile() to prevent renaming to duplicate names - Improve error handling in API endpoints with user-friendly messages - Add comprehensive test suite for duplicate name validation - Update CHANGELOG.md with fix details This fix prevents database constraint violations and provides clear error messages when users attempt to create or update profiles with names that already exist in the database.
This commit is contained in:
+10
-4
@@ -221,7 +221,10 @@ async def create_profile(
|
||||
"""Create a new voice profile."""
|
||||
try:
|
||||
return await profiles.create_profile(data, db)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
# Fallback for unexpected errors
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@@ -277,10 +280,13 @@ async def update_profile(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Update a voice profile."""
|
||||
profile = await profiles.update_profile(profile_id, data, db)
|
||||
if not profile:
|
||||
raise HTTPException(status_code=404, detail="Profile not found")
|
||||
return profile
|
||||
try:
|
||||
profile = await profiles.update_profile(profile_id, data, db)
|
||||
if not profile:
|
||||
raise HTTPException(status_code=404, detail="Profile not found")
|
||||
return profile
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@app.delete("/profiles/{profile_id}")
|
||||
|
||||
Reference in New Issue
Block a user