Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,17 @@ paths:
- in: query
name: status
schema:
type: string
enum:
[
pending,
votingPeriod,
passed,
rejected,
executedPassed,
executedRejected,
]
type: array
items:
enum:
[
pending,
votingPeriod,
passed,
rejected,
executedPassed,
executedRejected,
]
description: The status of the proposal
- in: query
name: kind
Expand Down Expand Up @@ -438,16 +439,17 @@ paths:
- in: query
name: status
schema:
type: string
enum:
[
pending,
votingPeriod,
passed,
rejected,
executedPassed,
executedRejected,
]
type: array
items:
enum:
[
pending,
votingPeriod,
passed,
rejected,
executedPassed,
executedRejected,
]
description: The status of the proposal
- in: query
name: kind
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/dto/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum ProposalKind {
pub struct ProposalQueryParams {
#[validate(range(min = 1, max = 10000))]
pub page: Option<u64>,
pub status: Option<ProposalStatus>,
pub status: Option<Vec<ProposalStatus>>,
pub kind: Option<ProposalKind>,
pub pattern: Option<String>,
}
Expand Down
5 changes: 3 additions & 2 deletions webserver/src/handler/governance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::Json;
use axum::extract::{Path, Query, State};
use axum::http::HeaderMap;
use axum_extra::extract::Query as QueryExt;
use axum_macros::debug_handler;

use crate::dto::governance::{ProposalQueryParams, ProposalVotesQueryparams};
Expand All @@ -13,7 +14,7 @@ use crate::state::common::CommonState;
#[debug_handler]
pub async fn get_governance_proposals(
_headers: HeaderMap,
Query(query): Query<ProposalQueryParams>,
QueryExt(query): QueryExt<ProposalQueryParams>,
State(state): State<CommonState>,
) -> Result<Json<PaginatedResponse<Vec<Proposal>>>, ApiError> {
let page = query.page.unwrap_or(1);
Expand All @@ -35,7 +36,7 @@ pub async fn get_governance_proposals(
#[debug_handler]
pub async fn get_all_governance_proposals(
_headers: HeaderMap,
Query(query): Query<ProposalQueryParams>,
QueryExt(query): QueryExt<ProposalQueryParams>,
State(state): State<CommonState>,
) -> Result<Json<Vec<Proposal>>, ApiError> {
let proposals = state
Expand Down
14 changes: 7 additions & 7 deletions webserver/src/repository/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ pub trait GovernanceRepoTrait {

async fn find_governance_proposals(
&self,
status: Option<GovernanceProposalResultDb>,
status: Option<Vec<GovernanceProposalResultDb>>,
kind: Option<GovernanceProposalKindDb>,
pattern: Option<String>,
page: i64,
) -> Result<PaginatedResponseDb<GovernanceProposalDb>, String>;

async fn find_all_governance_proposals(
&self,
status: Option<GovernanceProposalResultDb>,
status: Option<Vec<GovernanceProposalResultDb>>,
kind: Option<GovernanceProposalKindDb>,
pattern: Option<String>,
) -> Result<Vec<GovernanceProposalDb>, String>;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl GovernanceRepoTrait for GovernanceRepo {

async fn find_governance_proposals(
&self,
status: Option<GovernanceProposalResultDb>,
status: Option<Vec<GovernanceProposalResultDb>>,
kind: Option<GovernanceProposalKindDb>,
pattern: Option<String>,
page: i64,
Expand All @@ -91,7 +91,7 @@ impl GovernanceRepoTrait for GovernanceRepo {

async fn find_all_governance_proposals(
&self,
status: Option<GovernanceProposalResultDb>,
status: Option<Vec<GovernanceProposalResultDb>>,
kind: Option<GovernanceProposalKindDb>,
pattern: Option<String>,
) -> Result<Vec<GovernanceProposalDb>, String> {
Expand Down Expand Up @@ -187,15 +187,15 @@ impl GovernanceRepoTrait for GovernanceRepo {
impl<'a> GovernanceRepo {
fn governance_proposals(
&self,
status: Option<GovernanceProposalResultDb>,
status: Option<Vec<GovernanceProposalResultDb>>,
kind: Option<GovernanceProposalKindDb>,
pattern: Option<String>,
) -> IntoBoxed<'a, governance_proposals::table, Pg> {
let mut query = governance_proposals::table.into_boxed();

if let Some(status) = status {
query = query
.filter(governance_proposals::dsl::result.eq(status.clone()))
query =
query.filter(governance_proposals::dsl::result.eq_any(status))
}

if let Some(kind) = kind {
Expand Down
44 changes: 27 additions & 17 deletions webserver/src/service/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl GovernanceService {

pub async fn find_governance_proposals(
&self,
status: Option<ProposalStatus>,
status: Option<Vec<ProposalStatus>>,
kind: Option<ProposalKind>,
pattern: Option<String>,
page: u64,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl GovernanceService {

pub async fn find_all_governance_proposals(
&self,
status: Option<ProposalStatus>,
status: Option<Vec<ProposalStatus>>,
kind: Option<ProposalKind>,
pattern: Option<String>,
) -> Result<Vec<Proposal>, GovernanceError> {
Expand Down Expand Up @@ -232,21 +232,31 @@ impl GovernanceService {

fn map_status(
&self,
status: Option<ProposalStatus>,
) -> Option<GovernanceProposalResultDb> {
status.map(|s| match s {
ProposalStatus::Pending => GovernanceProposalResultDb::Pending,
ProposalStatus::VotingPeriod => {
GovernanceProposalResultDb::VotingPeriod
}
ProposalStatus::Passed => GovernanceProposalResultDb::Passed,
ProposalStatus::Rejected => GovernanceProposalResultDb::Rejected,
ProposalStatus::ExecutedPassed => {
GovernanceProposalResultDb::ExecutedPassed
}
ProposalStatus::ExecutedRejected => {
GovernanceProposalResultDb::ExecutedRejected
}
status: Option<Vec<ProposalStatus>>,
) -> Option<Vec<GovernanceProposalResultDb>> {
status.map(|s| {
s.iter()
.map(|s| match s {
ProposalStatus::Pending => {
GovernanceProposalResultDb::Pending
}
ProposalStatus::VotingPeriod => {
GovernanceProposalResultDb::VotingPeriod
}
ProposalStatus::Passed => {
GovernanceProposalResultDb::Passed
}
ProposalStatus::Rejected => {
GovernanceProposalResultDb::Rejected
}
ProposalStatus::ExecutedPassed => {
GovernanceProposalResultDb::ExecutedPassed
}
ProposalStatus::ExecutedRejected => {
GovernanceProposalResultDb::ExecutedRejected
}
})
.collect()
})
}

Expand Down
Loading