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:
@@ -83,6 +83,7 @@ def create_user(
|
||||
role=user_data.role,
|
||||
current_admin_id=current_admin.id,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
return UserDetailResponse(
|
||||
id=user.id,
|
||||
@@ -175,6 +176,7 @@ def update_user(
|
||||
role=update_data.get("role"),
|
||||
is_active=update_data.get("is_active"),
|
||||
)
|
||||
db.commit()
|
||||
|
||||
return UserDetailResponse(
|
||||
id=user.id,
|
||||
@@ -206,6 +208,7 @@ def toggle_user_status(
|
||||
user_id=user_id,
|
||||
current_admin_id=current_admin.id,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
return UserStatusToggleResponse(message=message, is_active=user.is_active)
|
||||
|
||||
@@ -222,5 +225,6 @@ def delete_user(
|
||||
user_id=user_id,
|
||||
current_admin_id=current_admin.id,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
return UserDeleteResponse(message=message)
|
||||
|
||||
Reference in New Issue
Block a user