Skip to content

Commit

Permalink
feat: Add blank implementation of the /api/v0/vote/active/plans end…
Browse files Browse the repository at this point in the history
…point (#134)

* add new endpoint

* add VotePlan object

* update

* fix fmt

* fix spell check

* remove unused fields

---------

Co-authored-by: Steven Johnson <[email protected]>
  • Loading branch information
Mr-Leshiy and stevenj authored Nov 16, 2023
1 parent 2d0ae61 commit b9f2aff
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
18 changes: 16 additions & 2 deletions catalyst-gateway/bin/src/service/api/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
//! `v0` Endpoints

use std::sync::Arc;

use poem::web::Data;
use poem_openapi::{payload::Binary, OpenApi};

use crate::service::common::tags::ApiTags;
use crate::{service::common::tags::ApiTags, state::State};

mod message_post;
mod plans_get;

/// `v0` API Endpoints
pub(crate) struct V0Api;

#[OpenApi(prefix_path = "/v0", tag = "ApiTags::V0")]
impl V0Api {
#[oai(path = "/message", method = "post", operation_id = "Message")]
/// Posts a signed transaction.
#[oai(path = "/message", method = "post", operation_id = "Message")]
async fn message_post(&self, message: Binary<Vec<u8>>) -> message_post::AllResponses {
message_post::endpoint(message).await
}

/// Get all active vote plans endpoint.
#[oai(
path = "/vote/active/plans",
method = "get",
operation_id = "GetActivePlans"
)]
async fn plans_get(&self, state: Data<&Arc<State>>) -> plans_get::AllResponses {
plans_get::endpoint(state).await
}
}

// Poem Tests cause license violation...
Expand Down
41 changes: 41 additions & 0 deletions catalyst-gateway/bin/src/service/api/v0/plans_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Implementation of the GET /vote/active/plans endpoint

use std::sync::Arc;

use poem::web::Data;
use poem_extensions::{response, UniResponse::T200};
use poem_openapi::payload::Json;

use crate::{
service::common::{
objects::vote_plan::VotePlan,
responses::{
resp_2xx::OK,
resp_5xx::{ServerError, ServiceUnavailable},
},
},
state::State,
};

/// All responses
pub(crate) type AllResponses = response! {
200: OK<Json<Vec<VotePlan>>>,
500: ServerError,
503: ServiceUnavailable,
};

/// GET /v0/vote/active/plans
///
/// Get all active vote plans endpoint.
///
/// ## Responses
///
/// * 200 with a JSON array with the list of vote plans with their respective data.
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
/// but unlikely)
/// * 503 Service Unavailable - Service has not started, do not send other requests.
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(_state: Data<&Arc<State>>) -> AllResponses {
// otherwise everything seems to be A-OK
T200(OK(Json(Vec::new())))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub(crate) type AllResponses = response! {
503: ServiceUnavailable,
};

#[allow(clippy::unused_async)]
/// GET /v1/votes/plans/account-votes/:account_id
///
/// Get votes for an `account_id` endpoint.
Expand All @@ -38,6 +37,7 @@ pub(crate) type AllResponses = response! {
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
/// but unlikely)
/// * 503 Service Unavailable - Service has not started, do not send other requests.
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(
_state: Data<&Arc<State>>, _account_id: Path<AccountId>,
) -> AllResponses {
Expand Down
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/service/common/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) mod delegate_public_key;
pub(crate) mod event_id;
pub(crate) mod fragments_processing_summary;
pub(crate) mod stake_public_key;
pub(crate) mod vote_plan;
pub(crate) mod voter_group_id;
pub(crate) mod voter_info;
pub(crate) mod voter_registration;
Expand Down
26 changes: 26 additions & 0 deletions catalyst-gateway/bin/src/service/common/objects/vote_plan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Define the Vote Plan

use poem_openapi::{types::Example, Object};

/// Vote Plan
#[derive(Object)]
#[oai(example = true)]
pub(crate) struct VotePlan {
/// Voting token identifier
#[oai(validator(
max_length = 121,
min_length = 59,
pattern = r"[0-9a-f]{56}\.[0-9a-f]{2,64}"
))]
voting_token: String,
}

impl Example for VotePlan {
fn example() -> Self {
Self {
voting_token:
"134c2d0a0b5761445d3f2d08492a5c193e3a19194453511426153630.0418401957301613"
.to_string(),
}
}
}

0 comments on commit b9f2aff

Please sign in to comment.