-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/poc-flutter-integration-tests
- Loading branch information
Showing
11 changed files
with
140 additions
and
107 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 was deleted.
Oops, something went wrong.
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
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
46 changes: 46 additions & 0 deletions
46
catalyst-gateway/bin/src/service/api/v1/account_votes_get.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,46 @@ | ||
//! Implementation of the `GET /v1/votes/plan/account-votes/:account_id` endpoint | ||
use std::sync::Arc; | ||
|
||
use poem::web::{Data, Path}; | ||
use poem_extensions::{response, UniResponse::T200}; | ||
use poem_openapi::payload::Json; | ||
|
||
use crate::{ | ||
service::common::{ | ||
objects::account_votes::{AccountId, AccountVote}, | ||
responses::{ | ||
resp_2xx::OK, | ||
resp_5xx::{ServerError, ServiceUnavailable}, | ||
}, | ||
}, | ||
state::State, | ||
}; | ||
|
||
/// All responses | ||
pub(crate) type AllResponses = response! { | ||
200: OK<Json<Vec<AccountVote>>>, | ||
500: ServerError, | ||
503: ServiceUnavailable, | ||
}; | ||
|
||
#[allow(clippy::unused_async)] | ||
/// GET /v1/votes/plans/account-votes/:account_id | ||
/// | ||
/// Get votes for an `account_id` endpoint. | ||
/// | ||
/// For each active vote plan, this endpoint returns an array | ||
/// with the proposal index number that the account voted for. | ||
/// | ||
/// ## Responses | ||
/// | ||
/// * 200 with a JSON array of the number of voted proposals in a plan. | ||
/// * 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. | ||
pub(crate) async fn endpoint( | ||
_state: Data<&Arc<State>>, _account_id: Path<AccountId>, | ||
) -> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! `v1` Endpoints | ||
use std::sync::Arc; | ||
|
||
use poem::web::{Data, Path}; | ||
use poem_openapi::OpenApi; | ||
|
||
use crate::{ | ||
service::common::{objects::account_votes::AccountId, tags::ApiTags}, | ||
state::State, | ||
}; | ||
|
||
mod account_votes_get; | ||
|
||
/// V1 API Endpoints | ||
pub(crate) struct V1Api; | ||
|
||
#[OpenApi(prefix_path = "/v1", tag = "ApiTags::V1")] | ||
impl V1Api { | ||
#[oai( | ||
path = "/votes/plan/account-votes/:account_id", | ||
method = "get", | ||
operation_id = "AccountVotes" | ||
)] | ||
/// Get from all active vote plans, the index of the voted proposals | ||
/// by th given account ID. | ||
async fn get_account_votes( | ||
&self, state: Data<&Arc<State>>, account_id: Path<AccountId>, | ||
) -> account_votes_get::AllResponses { | ||
account_votes_get::endpoint(state, account_id).await | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
catalyst-gateway/bin/src/service/common/objects/account_votes.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,48 @@ | ||
//! Define the Account Votes. | ||
use poem_openapi::{types::Example, NewType, Object}; | ||
use serde::Deserialize; | ||
|
||
#[derive(NewType, Deserialize)] | ||
#[oai(example = true)] | ||
/// Unique ID of a user account. | ||
pub(crate) struct AccountId( | ||
#[oai(validator(max_length = 64, min_length = 64, pattern = "[0-9a-f]{64}"))] String, | ||
); | ||
|
||
impl Example for AccountId { | ||
fn example() -> Self { | ||
Self("a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663".into()) | ||
} | ||
} | ||
|
||
#[derive(NewType, Deserialize)] | ||
#[oai(example = true)] | ||
/// Unique ID of a vote plan. | ||
pub(crate) struct VotePlanId(String); | ||
|
||
impl Example for VotePlanId { | ||
fn example() -> Self { | ||
Self("a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663".into()) | ||
} | ||
} | ||
|
||
#[derive(Object, Deserialize)] | ||
#[oai(example = true)] | ||
/// Indexes of a proposal that the account has voted for across all active vote plans. | ||
pub(crate) struct AccountVote { | ||
#[oai(validator(max_length = 64, min_length = 64, pattern = "[0-9a-f]{64}"))] | ||
/// The hex-encoded ID of the vote plan. | ||
pub(crate) vote_plan_id: VotePlanId, | ||
/// Array of the proposal numbers voted for by the account ID within the vote plan. | ||
pub(crate) votes: Vec<u8>, | ||
} | ||
|
||
impl Example for AccountVote { | ||
fn example() -> Self { | ||
Self { | ||
vote_plan_id: VotePlanId::example(), | ||
votes: vec![1, 3, 9, 123], | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.