Skip to content

Commit

Permalink
feat(fragments-endpoints): Add /fragments and /fragments/statuses com…
Browse files Browse the repository at this point in the history
…patibility endpoints
  • Loading branch information
Felipe Rosa committed Nov 1, 2023
1 parent 9674ce4 commit c6eda2f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
27 changes: 27 additions & 0 deletions catalyst-gateway/bin/src/service/api/fragments/index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Implementation of the GET /fragments endpoint
use poem_extensions::response;
use poem_extensions::UniResponse::T204;

use crate::service::common::responses::resp_2xx::NoContent;
use crate::service::common::responses::resp_5xx::{ServerError, ServiceUnavailable};

/// All responses
pub(crate) type AllResponses = response! {
204: NoContent,
500: ServerError,
503: ServiceUnavailable,
};

/// # GET /fragments
///
/// TODO
///
/// ## Responses
///
/// * 204 No Content - Service is OK and can keep running.
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible but unlikely)
/// * 503 Service Unavailable - Service is possibly not running reliably.
pub(crate) async fn endpoint() -> AllResponses {
T204(NoContent)
}
23 changes: 23 additions & 0 deletions catalyst-gateway/bin/src/service/api/fragments/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Fragment endpoints
mod index;
mod statuses;

use crate::service::common::tags::ApiTags;
use poem_openapi::OpenApi;

/// All Responses
pub(crate) struct FragmentsApi;

#[OpenApi(prefix_path = "/fragments", tag = "ApiTags::Fragments")]
impl FragmentsApi {
#[oai(path = "/", method = "get", operation_id = "fragments")]
async fn index(&self) -> index::AllResponses {
index::endpoint().await
}

#[oai(path = "/statuses", method = "get", operation_id = "fragmentsStatuses")]
async fn statuses(&self) -> statuses::AllResponses {
statuses::endpoint().await
}
}
27 changes: 27 additions & 0 deletions catalyst-gateway/bin/src/service/api/fragments/statuses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Implementation of the GET /fragments/statuses endpoint
use poem_extensions::response;
use poem_extensions::UniResponse::T204;

use crate::service::common::responses::resp_2xx::NoContent;
use crate::service::common::responses::resp_5xx::{ServerError, ServiceUnavailable};

/// All responses
pub(crate) type AllResponses = response! {
204: NoContent,
500: ServerError,
503: ServiceUnavailable,
};

/// # GET /fragments/statuses
///
/// TODO
///
/// ## Responses
///
/// * 204 No Content - Service is OK and can keep running.
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible but unlikely)
/// * 503 Service Unavailable - Service is possibly not running reliably.
pub(crate) async fn endpoint() -> AllResponses {
T204(NoContent)
}
11 changes: 7 additions & 4 deletions catalyst-gateway/bin/src/service/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use v0::V0Api;

use crate::settings::API_URL_PREFIX;

use self::fragments::FragmentsApi;

mod fragments;
mod health;
mod registration;
mod test_endpoints;
Expand Down Expand Up @@ -58,12 +61,12 @@ fn get_api_license() -> LicenseObject {
const TERMS_OF_SERVICE: &str =
"https://github.com/input-output-hk/catalyst-core/blob/main/book/src/98_CODE_OF_CONDUCT.md";

type ApiComponents = (TestApi, HealthApi, V0Api, RegistrationApi, FragmentsApi);

/// Create the `OpenAPI` definition
pub(crate) fn mk_api(
hosts: Vec<String>,
) -> OpenApiService<(TestApi, HealthApi, V0Api, RegistrationApi), ()> {
pub(crate) fn mk_api(hosts: Vec<String>) -> OpenApiService<ApiComponents, ()> {
let mut service = OpenApiService::new(
(TestApi, HealthApi, V0Api, RegistrationApi),
(TestApi, HealthApi, V0Api, RegistrationApi, FragmentsApi),
API_TITLE,
API_VERSION,
)
Expand Down
2 changes: 2 additions & 0 deletions catalyst-gateway/bin/src/service/common/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use poem_openapi::Tags;
/// `OpenAPI` Tags
#[derive(Tags)]
pub(crate) enum ApiTags {
/// Fragment endpoints
Fragments,
/// Health Endpoints
Health,
/// Information relating to Voter Registration, Delegations and Calculated Voting
Expand Down

0 comments on commit c6eda2f

Please sign in to comment.