Skip to content

Commit

Permalink
fix: update openapi response types, add missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed May 17, 2024
1 parent 95afebd commit ef7795c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
9 changes: 6 additions & 3 deletions catalyst-gateway/bin/src/event_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ pub(crate) struct EventDB {
inspection_settings: Arc<RwLock<DatabaseInspectionSettings>>,
}

/// No DB URL was provided
/// `EventDB` Errors
#[derive(thiserror::Error, Debug, PartialEq, Eq)]
pub(crate) enum Error {
/// Database statement is not a valid modify statement
#[error("Invalid Modify Statement")]
InvalidModifyStatement,
/// Database statement is not a valid query statement
#[error("Invalid Query Statement")]
InvalidQueryStatement,
/// No DB URL was provided
#[error("DB URL is undefined")]
NoDatabaseUrlError,
NoDatabaseUrl,
}

impl EventDB {
Expand Down Expand Up @@ -230,7 +233,7 @@ pub(crate) async fn establish_connection(url: Option<String>) -> anyhow::Result<
let database_url = match url {
Some(url) => url,
// If the Database connection URL is not supplied, try and get from the env var.
None => std::env::var(DATABASE_URL_ENVVAR).map_err(|_| Error::NoDatabaseUrlError)?,
None => std::env::var(DATABASE_URL_ENVVAR).map_err(|_| Error::NoDatabaseUrl)?,
};

let config = tokio_postgres::config::Config::from_str(&database_url)?;
Expand Down
27 changes: 13 additions & 14 deletions catalyst-gateway/bin/src/service/api/health/inspection_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
use std::sync::Arc;

use poem::web::Data;
use poem_extensions::{response, UniResponse::T204};
use poem_openapi::ApiResponse;
use tracing::{debug, error};

use crate::{
logger::LogLevel,
service::common::responses::{
resp_2xx::NoContent,
resp_4xx::ApiValidationError,
resp_5xx::{ServerError, ServiceUnavailable},
},
service::common::responses::WithErrorResponses,
state::{DeepQueryInspection, State},
};

/// All responses
pub(crate) type AllResponses = response! {
204: NoContent,
400: ApiValidationError,
500: ServerError,
503: ServiceUnavailable,
};
/// Endpoint responses.
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// Service is Started and can serve requests.
#[oai(status = 204)]
NoContent,
}

/// All responses.
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// # GET /health/inspection
///
Expand Down Expand Up @@ -61,5 +60,5 @@ pub(crate) async fn endpoint(
);
}
// otherwise everything seems to be A-OK
T204(NoContent)
Responses::NoContent.into()
}

0 comments on commit ef7795c

Please sign in to comment.