Skip to content

Commit

Permalink
Update async-grapql version
Browse files Browse the repository at this point in the history
Use new OutputJson for VoteOptions
Removed unnecessary code
  • Loading branch information
danielsanchezq committed Jul 8, 2020
1 parent 6cef2cb commit 64ccae3
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vit-servicing-station-lib/Cargo.toml
Expand Up @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-graphql = "1.16.2"
async-graphql-warp = "1.16.2"
async-graphql = "1.16.8"
async-graphql-warp = "1.16.6"
async-trait = "0.1.33"
base64 = "0.12.1"
chrono = { version = "0.4", features = ["serde"] }
Expand Down
4 changes: 3 additions & 1 deletion vit-servicing-station-lib/src/db/models/vote_options.rs
Expand Up @@ -2,8 +2,10 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

pub type VoteOptionsMap = HashMap<String, u8>;

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct VoteOptions(pub HashMap<String, u8>);
pub struct VoteOptions(pub VoteOptionsMap);

impl VoteOptions {
pub fn parse_coma_separated_value(csv: &str) -> VoteOptions {
Expand Down
Expand Up @@ -8,43 +8,52 @@ use async_graphql::Context;

#[async_graphql::Object]
impl Fund {
#[field(desc = "Fund ID")]
pub async fn id(&self) -> i32 {
self.id
}

#[field(desc = "Fund Name")]
pub async fn fund_name(&self) -> &str {
&self.fund_name
}

#[field(desc = "Fund Goal")]
pub async fn fund_goal(&self) -> &str {
&self.fund_goal
}

#[field(desc = "Fund voting information")]
pub async fn voting_power_info(&self) -> &str {
&self.voting_power_info
}

#[field(desc = "Fund rewards information")]
pub async fn rewards_info(&self) -> &str {
&self.rewards_info
}

#[field(desc = "Fund start time, rfc3339 formatted")]
pub async fn fund_start_time(&self) -> String {
unix_timestamp_to_datetime(self.fund_start_time).to_rfc3339()
}

#[field(desc = "Fund end time, rfc3339 formatted")]
pub async fn fund_end_time(&self) -> String {
unix_timestamp_to_datetime(self.fund_end_time).to_rfc3339()
}

#[field(desc = "Next fund start time, rfc3339 formatted")]
pub async fn next_fund_start_time(&self) -> String {
unix_timestamp_to_datetime(self.next_fund_start_time).to_rfc3339()
}

#[field(desc = "Fund chain voteplans")]
pub async fn chain_vote_plans(
&self,
ctx: &Context<'_>,
) -> async_graphql::FieldResult<Vec<Voteplan>> {
let pool = ctx.data::<db::DBConnectionPool>();
let pool = ctx.data::<db::DBConnectionPool>().unwrap();
voteplans_queries::query_voteplan_by_id(self.id, pool)
.await
.map_err(async_graphql::FieldError::from)
Expand Down
@@ -1,6 +1,5 @@
pub mod funds;
pub mod proposals;
pub mod vote_options;
pub mod voteplans;

use crate::db;
Expand Down
@@ -1,6 +1,8 @@
use crate::db::models::proposals::{Category, Proposal, Proposer};
use crate::db::models::vote_options::VoteOptions;
use crate::utils::datetime::unix_timestamp_to_datetime;
use async_graphql::OutputJson;

#[async_graphql::Object]
impl Category {
pub async fn category_id(&self) -> &str {
Expand Down Expand Up @@ -109,8 +111,8 @@ impl Proposal {
unix_timestamp_to_datetime(self.chain_committee_end_time).to_rfc3339()
}

pub async fn chain_vote_options(&self) -> VoteOptions {
self.chain_vote_options.clone()
pub async fn chain_vote_options(&self) -> OutputJson<&VoteOptions> {
OutputJson(&self.chain_vote_options)
}

pub async fn fund_id(&self) -> i32 {
Expand Down

This file was deleted.

0 comments on commit 64ccae3

Please sign in to comment.