diff --git a/src/errors.rs b/src/errors.rs index 2df91ae..3cd9934 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -25,10 +25,15 @@ use tracing::error; pub enum ApiError { #[error("Internal Server Error")] InternalServerError, + #[error("Not Found")] NotFound, + #[error("Not Found Playbook: {0}")] NotFoundPlaybook(HTTPError), + + #[error("Failed to create playbook: {0}")] + FailedToCreatePlaybook(HTTPError), } impl IntoResponse for ApiError { @@ -37,7 +42,9 @@ impl IntoResponse for ApiError { Self::InternalServerError => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()), Self::NotFound => (StatusCode::NOT_FOUND, self.to_string()), Self::NotFoundPlaybook(e) => (StatusCode::NOT_FOUND, e.to_string()), + Self::FailedToCreatePlaybook(e) => (StatusCode::BAD_REQUEST, e.to_string()), }; + error!("{} - {}", status, message); (status, Json(json!({ "message": message }))).into_response() } diff --git a/src/handlers/playbook.rs b/src/handlers/playbook.rs index b1062fa..8718523 100644 --- a/src/handlers/playbook.rs +++ b/src/handlers/playbook.rs @@ -37,7 +37,7 @@ use crate::services::playbook::PlaybookService; content_type = "application/json" ), responses( - (status = 201, description = "Playbook created successfully", body = PlaybookResponse) + (status = 201, description = "Playbook created successfully", body = PlaybookSpec) ), tag = "Playbooks" )] diff --git a/src/responses/playbook.rs b/src/responses/playbook.rs index f53b570..9f27716 100644 --- a/src/responses/playbook.rs +++ b/src/responses/playbook.rs @@ -14,24 +14,9 @@ use amp_common::scm::content::Content; use amp_common::scm::git::Tree; -use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; -#[derive(Serialize, Deserialize, ToSchema)] -pub struct PlaybookResponse { - /// The playbook ID in Amphitheatre. - pub id: String, - /// The title of the playbook. - pub title: String, - /// The description of the playbook. - pub description: String, - /// When the playbook was created in Amphitheatre. - pub created_at: DateTime, - /// When the playbook was last updated in Amphitheatre. - pub updated_at: DateTime, -} - #[derive(Serialize, Deserialize, ToSchema)] pub struct FilesResponse { /// The file details. diff --git a/src/services/playbook.rs b/src/services/playbook.rs index f4145a5..ffd17d8 100644 --- a/src/services/playbook.rs +++ b/src/services/playbook.rs @@ -80,12 +80,12 @@ impl PlaybookService { } pub async fn create(ctx: Arc, req: &CreatePlaybookRequest) -> Result { - let playbook_payload = PlaybookPayload { + let payload = PlaybookPayload { title: req.title.clone(), description: req.description.clone().unwrap_or_default(), preface: req.preface.clone(), }; - ctx.client.playbooks().create(playbook_payload).map_err(ApiError::NotFoundPlaybook) + ctx.client.playbooks().create(payload).map_err(ApiError::FailedToCreatePlaybook) } pub async fn update(ctx: Arc, id: Uuid, req: Synchronization) -> Result { diff --git a/src/swagger.rs b/src/swagger.rs index 965ef9b..9ed1f66 100644 --- a/src/swagger.rs +++ b/src/swagger.rs @@ -15,7 +15,7 @@ use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; -use crate::{handlers, requests, responses}; +use crate::{handlers, requests}; #[derive(OpenApi)] #[openapi( @@ -31,7 +31,6 @@ use crate::{handlers, requests, responses}; schemas( requests::playbook::CreatePlaybookRequest, requests::playbook::UpdatePlaybookRequest, - responses::playbook::PlaybookResponse, amp_common::resource::ActorSpec, amp_common::resource::CharacterSpec,