refactor: move transaction management from services to API endpoints

- Services now use db.flush() instead of db.commit() for database operations
- API endpoints handle transaction commit after service calls
- Remove db.rollback() from services (let exception handlers manage this)
- Ensures consistent transaction boundaries at API layer

This pattern gives API endpoints full control over when to commit,
allowing for better error handling and potential multi-operation transactions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-06 18:34:41 +01:00
parent 5d40551d98
commit 3520bcb069
33 changed files with 118 additions and 119 deletions

View File

@@ -135,7 +135,7 @@ class TeamService:
vendor_user.is_active = update_data["is_active"]
vendor_user.updated_at = datetime.now(UTC)
db.commit()
db.flush()
db.refresh(vendor_user)
return {
@@ -144,7 +144,6 @@ class TeamService:
}
except Exception as e:
db.rollback()
logger.error(f"Error updating team member: {str(e)}")
raise ValidationException("Failed to update team member")
@@ -178,13 +177,11 @@ class TeamService:
# Soft delete
vendor_user.is_active = False
vendor_user.updated_at = datetime.now(UTC)
db.commit()
logger.info(f"Removed user {user_id} from vendor {vendor_id}")
return True
except Exception as e:
db.rollback()
logger.error(f"Error removing team member: {str(e)}")
raise ValidationException("Failed to remove team member")