-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5192 from systeminit/migrate-workspace-endpoints
chore(sdf): Migrate workspace API endpoints to v2
- Loading branch information
Showing
7 changed files
with
150 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::{app_state::AppState, service::ApiError}; | ||
use axum::{ | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
routing::post, | ||
Router, | ||
}; | ||
use dal::{TransactionsError, UserError, UserPk, WorkspaceError, WorkspacePk}; | ||
use thiserror::Error; | ||
|
||
mod export_workspace; | ||
mod install_workspace; | ||
|
||
#[remain::sorted] | ||
#[derive(Debug, Error)] | ||
pub enum WorkspaceAPIError { | ||
#[error("Trying to export from/import into root tenancy")] | ||
ExportingImportingWithRootTenancy, | ||
#[error("invalid user: {0}")] | ||
InvalidUser(UserPk), | ||
#[error("Module index: {0}")] | ||
ModuleIndex(#[from] module_index_client::ModuleIndexClientError), | ||
#[error("Module index not configured")] | ||
ModuleIndexNotConfigured, | ||
#[error("transactions error: {0}")] | ||
Transactions(#[from] TransactionsError), | ||
#[error("Unable to parse URL: {0}")] | ||
Url(#[from] url::ParseError), | ||
#[error("user error: {0}")] | ||
User(#[from] UserError), | ||
#[error("workspace error: {0}")] | ||
Workspace(#[from] WorkspaceError), | ||
#[error("Could not find current workspace {0}")] | ||
WorkspaceNotFound(WorkspacePk), | ||
} | ||
|
||
pub type WorkspaceAPIResult<T> = Result<T, WorkspaceAPIError>; | ||
|
||
impl IntoResponse for WorkspaceAPIError { | ||
fn into_response(self) -> Response { | ||
let (status_code, error_message) = match self { | ||
WorkspaceAPIError::WorkspaceNotFound(_) => (StatusCode::NOT_FOUND, self.to_string()), | ||
_ => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()), | ||
}; | ||
|
||
ApiError::new(status_code, error_message).into_response() | ||
} | ||
} | ||
|
||
pub fn v2_routes() -> Router<AppState> { | ||
Router::new() | ||
.route("/install", post(install_workspace::install_workspace)) | ||
.route("/export", post(export_workspace::export_workspace)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.