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:
@@ -3,7 +3,7 @@ use uuid::Uuid;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::models::common::Role;
|
||||
use crate::models::workspaces::WorkspaceBilling;
|
||||
use crate::models::workspaces::{Workspace, WorkspaceBilling};
|
||||
use crate::service::WorkspaceService;
|
||||
use crate::session::Session;
|
||||
|
||||
@@ -20,27 +20,25 @@ impl WorkspaceService {
|
||||
pub async fn workspace_billing(
|
||||
&self,
|
||||
ctx: &Session,
|
||||
workspace_id: Uuid,
|
||||
ws: &Workspace,
|
||||
) -> Result<WorkspaceBilling, 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, Role::Owner)
|
||||
.await?;
|
||||
self.ensure_workspace_billing(workspace_id).await
|
||||
self.ensure_workspace_billing(ws.id).await
|
||||
}
|
||||
|
||||
pub async fn workspace_update_billing(
|
||||
&self,
|
||||
ctx: &Session,
|
||||
workspace_id: Uuid,
|
||||
ws: &Workspace,
|
||||
params: UpdateBillingParams,
|
||||
) -> Result<WorkspaceBilling, 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, Role::Owner)
|
||||
.await?;
|
||||
|
||||
let current = self.ensure_workspace_billing(workspace_id).await?;
|
||||
let current = self.ensure_workspace_billing(ws.id).await?;
|
||||
let plan = params.plan.unwrap_or(current.plan.clone());
|
||||
let billing_email = merge_optional_text(params.billing_email, current.billing_email);
|
||||
let seats = params.seats.unwrap_or(current.seats);
|
||||
@@ -70,7 +68,7 @@ impl WorkspaceService {
|
||||
.bind(&billing_email)
|
||||
.bind(seats)
|
||||
.bind(now)
|
||||
.bind(workspace_id)
|
||||
.bind(ws.id)
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
Reference in New Issue
Block a user