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

@@ -194,8 +194,8 @@ class VendorThemeService:
# Update theme fields
self._apply_theme_updates(theme, theme_data)
# Commit changes
db.commit()
# Flush changes
db.flush()
db.refresh(theme)
self.logger.info(f"Theme updated successfully for vendor {vendor_code}")
@@ -206,7 +206,6 @@ class VendorThemeService:
raise
except Exception as e:
db.rollback()
self.logger.error(f"Failed to update theme for vendor {vendor_code}: {e}")
raise ThemeOperationException(
operation="update", vendor_code=vendor_code, reason=str(e)
@@ -312,8 +311,8 @@ class VendorThemeService:
# Apply preset using helper function
apply_preset(theme, preset_name)
# Commit changes
db.commit()
# Flush changes
db.flush()
db.refresh(theme)
self.logger.info(
@@ -326,7 +325,6 @@ class VendorThemeService:
raise
except Exception as e:
db.rollback()
self.logger.error(f"Failed to apply preset to vendor {vendor_code}: {e}")
raise ThemeOperationException(
operation="apply_preset", vendor_code=vendor_code, reason=str(e)
@@ -386,7 +384,6 @@ class VendorThemeService:
# Delete theme
db.delete(theme)
db.commit()
self.logger.info(f"Theme deleted for vendor {vendor_code}")
return {
@@ -398,7 +395,6 @@ class VendorThemeService:
raise
except Exception as e:
db.rollback()
self.logger.error(f"Failed to delete theme for vendor {vendor_code}: {e}")
raise ThemeOperationException(
operation="delete", vendor_code=vendor_code, reason=str(e)