Skip to content

Commit

Permalink
Fix fragment status object format and implement PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Rosa committed Nov 15, 2023
1 parent 89f7230 commit 34843b1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 65 deletions.
40 changes: 0 additions & 40 deletions catalyst-gateway/bin/src/service/api/fragments/mod.rs

This file was deleted.

23 changes: 2 additions & 21 deletions catalyst-gateway/bin/src/service/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use test_endpoints::TestApi;
use v0::V0Api;
use v1::V1Api;

use self::fragments::FragmentsApi;
use crate::settings::API_URL_PREFIX;

mod fragments;
mod health;
mod registration;
mod test_endpoints;
Expand Down Expand Up @@ -65,26 +63,9 @@ const TERMS_OF_SERVICE: &str =
/// Create the `OpenAPI` definition
pub(crate) fn mk_api(
hosts: Vec<String>,
) -> OpenApiService<
(
TestApi,
HealthApi,
RegistrationApi,
V0Api,
V1Api,
FragmentsApi,
),
(),
> {
) -> OpenApiService<(TestApi, HealthApi, RegistrationApi, V0Api, V1Api), ()> {
let mut service = OpenApiService::new(
(
TestApi,
HealthApi,
RegistrationApi,
V0Api,
V1Api,
FragmentsApi,
),
(TestApi, HealthApi, RegistrationApi, V0Api, V1Api),
API_TITLE,
API_VERSION,
)
Expand Down
44 changes: 42 additions & 2 deletions catalyst-gateway/bin/src/service/api/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
use std::sync::Arc;

use poem::web::{Data, Path};
use poem_openapi::OpenApi;
use poem_openapi::{param::Query, payload::Json, OpenApi};

use crate::{
service::common::{objects::account_votes::AccountId, tags::ApiTags},
service::common::{
objects::{account_votes::AccountId, fragments_batch::FragmentsBatch},
tags::ApiTags,
},
state::State,
};

mod account_votes_get;
mod fragments_post;
mod fragments_statuses;

/// V1 API Endpoints
pub(crate) struct V1Api;
Expand All @@ -29,4 +34,39 @@ impl V1Api {
) -> account_votes_get::AllResponses {
account_votes_get::endpoint(state, account_id).await
}

/// Process fragments
///
/// Posts a fragments batch to be processed.
#[oai(
path = "/fragments",
method = "post",
operation_id = "fragments",
tag = "ApiTags::Fragments"
)]
async fn fragments_post(
&self,
/// Batch of fragments to be processed.
Json(fragments_batch): Json<FragmentsBatch>,
) -> fragments_post::AllResponses {
fragments_post::endpoint(fragments_batch).await
}

/// Get Fragment Statuses
///
/// Get statuses of the fragments with the given ids.
#[oai(
path = "/fragments/statuses",
method = "get",
operation_id = "fragmentsStatuses",
tag = "ApiTags::Fragments"
)]
async fn fragments_statuses(
&self,
/// Comma-separated list of fragment ids for which the statuses will
/// be retrieved.
Query(fragment_ids): Query<fragments_statuses::FragmentIds>,
) -> fragments_statuses::AllResponses {
fragments_statuses::endpoint(fragment_ids).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ impl Example for StatusRejected {
/// Fragment is included in a block.
pub(crate) struct StatusInABlock {
pub date: BlockDate,
pub hash: Hash,
pub block: Hash,
}

impl Example for StatusInABlock {
fn example() -> Self {
Self {
date: BlockDate::example(),
hash: Hash::example(),
block: Hash::example(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/service/common/objects/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use poem_openapi::{types::Example, Object};
/// Blake2b256 hash wrapper.
pub(crate) struct Hash {
/// Blake2b256 hash encoded in hex.
#[oai(validator(max_length = 64, min_length = 64, pattern = "[0-9a-f]{64}"))]
pub hash: String,
}

Expand Down

0 comments on commit 34843b1

Please sign in to comment.