-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add blank implementation of the
/api/v0/vote/active/plans
end…
…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
Showing
5 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
catalyst-gateway/bin/src/service/common/objects/vote_plan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} | ||
} |