refactor(workspace): pass workspace object instead of id to service methods
- Replace workspace_id parameter with Workspace object reference in all workspace service methods - Remove redundant find_workspace_by_id calls that were duplicated in each method - Update all method signatures across approval, audit, billing, branding, core, settings and stats modules - Modify SQL queries to bind ws.id instead of separate workspace_id parameter - Add Workspace import to all affected modules - Adjust method calls in API handlers to pass workspace object instead of id - Consolidate workspace retrieval logic to single location per operation flow
This commit is contained in:
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::models::workspaces::WorkspaceSettings;
|
||||
use crate::models::workspaces::{Workspace, WorkspaceSettings};
|
||||
use crate::service::WorkspaceService;
|
||||
use crate::session::Session;
|
||||
|
||||
@@ -24,26 +24,24 @@ impl WorkspaceService {
|
||||
pub async fn workspace_settings(
|
||||
&self,
|
||||
ctx: &Session,
|
||||
workspace_id: Uuid,
|
||||
ws: &Workspace,
|
||||
) -> Result<WorkspaceSettings, AppError> {
|
||||
let user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
|
||||
let ws = self.find_workspace_by_id(workspace_id).await?;
|
||||
self.ensure_workspace_readable(user_uid, &ws).await?;
|
||||
self.ensure_user_workspace_settings(workspace_id).await
|
||||
self.ensure_user_workspace_settings(ws.id).await
|
||||
}
|
||||
|
||||
pub async fn workspace_update_settings(
|
||||
&self,
|
||||
ctx: &Session,
|
||||
workspace_id: Uuid,
|
||||
ws: &Workspace,
|
||||
params: UpdateWorkspaceSettingsParams,
|
||||
) -> Result<WorkspaceSettings, AppError> {
|
||||
let user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
|
||||
let ws = self.find_workspace_by_id(workspace_id).await?;
|
||||
self.ensure_workspace_role_at_least(user_uid, &ws, crate::models::common::Role::Admin)
|
||||
.await?;
|
||||
|
||||
let current = self.ensure_user_workspace_settings(workspace_id).await?;
|
||||
let current = self.ensure_user_workspace_settings(ws.id).await?;
|
||||
let now = chrono::Utc::now();
|
||||
let mut txn = self
|
||||
.ctx
|
||||
@@ -77,7 +75,7 @@ impl WorkspaceService {
|
||||
.bind(params.pull_requests_enabled.unwrap_or(current.pull_requests_enabled))
|
||||
.bind(params.wiki_enabled.unwrap_or(current.wiki_enabled))
|
||||
.bind(now)
|
||||
.bind(workspace_id)
|
||||
.bind(ws.id)
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
Reference in New Issue
Block a user