Skip to content

Commit

Permalink
add challenge_url to challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Jan 26, 2021
1 parent 5a9504a commit bae31f3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/api/v0.yaml
Expand Up @@ -243,6 +243,8 @@ components:
fund_id:
type: integer
format: int32
challenge_url:
type: string

ChallengeWithProposals:
allOf:
Expand Down
8 changes: 4 additions & 4 deletions resources/tests/csvs/challenges.csv
@@ -1,4 +1,4 @@
id,title,description,rewards_total,fund_id
1,Challenge 1,Something,9000,-1
2,Challenge 2,Hey hey hey,100500,-1
3,Challenge 3,Another one,420000,-1
id,title,description,rewards_total,fund_id,challenge_url
1,Challenge 1,Something,9000,-1,http://example.com/challenges/1
2,Challenge 2,Hey hey hey,100500,-1,http://example.com/challenges/2
3,Challenge 3,Another one,420000,-1,http://example.com/challenges/3
Expand Up @@ -66,7 +66,8 @@ create table challenges
title VARCHAR NOT NULL,
description VARCHAR NOT NULL,
rewards_total BIGINT NOT NULL,
fund_id INTEGER NOT NULL
fund_id INTEGER NOT NULL,
challenge_url VARCHAR NOT NULL
);

CREATE VIEW full_proposals_info
Expand Down
9 changes: 9 additions & 0 deletions vit-servicing-station-lib/src/db/models/challenges.rs
Expand Up @@ -11,6 +11,8 @@ pub struct Challenge {
pub rewards_total: i64,
#[serde(alias = "fundId")]
pub fund_id: i32,
#[serde(alias = "challengeUrl")]
pub challenge_url: String,
}

impl Queryable<challenges::SqlType, DB> for Challenge {
Expand All @@ -25,6 +27,8 @@ impl Queryable<challenges::SqlType, DB> for Challenge {
i64,
// 4 -> fund_id
i32,
// 5 -> fund_url
String,
);

fn build(row: Self::Row) -> Self {
Expand All @@ -34,6 +38,7 @@ impl Queryable<challenges::SqlType, DB> for Challenge {
description: row.2,
rewards_total: row.3,
fund_id: row.4,
challenge_url: row.5,
}
}
}
Expand All @@ -46,6 +51,7 @@ impl Insertable<challenges::table> for Challenge {
diesel::dsl::Eq<challenges::description, String>,
diesel::dsl::Eq<challenges::rewards_total, i64>,
diesel::dsl::Eq<challenges::fund_id, i32>,
diesel::dsl::Eq<challenges::challenge_url, String>,
);

fn values(self) -> Self::Values {
Expand All @@ -55,6 +61,7 @@ impl Insertable<challenges::table> for Challenge {
challenges::description.eq(self.description),
challenges::rewards_total.eq(self.rewards_total),
challenges::fund_id.eq(self.fund_id),
challenges::challenge_url.eq(self.challenge_url),
)
}
}
Expand All @@ -74,6 +81,7 @@ pub mod test {
description: "challenge description".to_string(),
rewards_total: REWARDS_TOTAL,
fund_id,
challenge_url: "http://example.com/".to_string(),
}
}

Expand All @@ -86,6 +94,7 @@ pub mod test {
challenges::description.eq(challenge.description.clone()),
challenges::rewards_total.eq(challenge.rewards_total),
challenges::fund_id.eq(challenge.fund_id),
challenges::challenge_url.eq(challenge.challenge_url.clone()),
);

diesel::insert_into(challenges::table)
Expand Down
1 change: 1 addition & 0 deletions vit-servicing-station-lib/src/db/schema.rs
Expand Up @@ -13,6 +13,7 @@ table! {
description -> Text,
rewards_total -> BigInt,
fund_id -> Integer,
challenge_url -> Text,
}
}

Expand Down
6 changes: 4 additions & 2 deletions vit-servicing-station-lib/src/v0/endpoints/graphql/routes.rs
Expand Up @@ -77,7 +77,8 @@ mod test {
title
description
rewardsTotal
fundId
fundId
challengeUrl
},
}
}"#;
Expand Down Expand Up @@ -109,6 +110,7 @@ mod test {
description
rewardsTotal
fundId
challengeUrl
},
}
}"#;
Expand Down Expand Up @@ -147,7 +149,7 @@ mod test {
chainVoteStartTime,
chainVoteEndTime,
chainCommitteeEndTime,
fundId
fundId,
challengeId
}
}"#;
Expand Down
Expand Up @@ -26,4 +26,9 @@ impl Challenge {
pub async fn fund_id(&self) -> i32 {
self.fund_id
}

/// Challenge information link
pub async fn challenge_url(&self) -> &str {
&self.challenge_url
}
}
Expand Up @@ -26,6 +26,7 @@
description,
rewardsTotal,
fundId,
challengeUrl,
},
}
}"
Expand Down
Expand Up @@ -18,6 +18,7 @@
chainVoteplanPayload
chainVoteEncryptionKey
fundId
challengeUrl
}
}
}"
Expand Down
Expand Up @@ -26,6 +26,7 @@
description,
rewardsTotal,
fundId,
challengeUrl,
},
}
}"
Expand Down
10 changes: 9 additions & 1 deletion vit-servicing-station-tests/src/common/data/csv_converter.rs
Expand Up @@ -93,7 +93,14 @@ impl CsvConverter {
challenges: Vec<Challenge>,
path: P,
) -> Result<(), Error> {
let headers = vec!["id", "title", "description", "rewards_total", "fund_id"];
let headers = vec![
"id",
"title",
"description",
"rewards_total",
"fund_id",
"challenge_url",
];

let content: Vec<Vec<String>> = challenges.iter().map(|x| convert_challenge(x)).collect();
self.build_file(headers, content, path)
Expand Down Expand Up @@ -181,5 +188,6 @@ fn convert_challenge(challenge: &Challenge) -> Vec<String> {
challenge.description.clone(),
challenge.rewards_total.to_string(),
challenge.fund_id.to_string(),
challenge.challenge_url.clone(),
]
}
Expand Up @@ -242,6 +242,7 @@ impl ArbitraryGenerator {
description: Buzzword().fake::<String>(),
rewards_total: 100500,
fund_id,
challenge_url: self.gen_http_address(),
}
}

Expand Down
1 change: 1 addition & 0 deletions vit-servicing-station-tests/src/common/db/mod.rs
Expand Up @@ -131,6 +131,7 @@ impl<'a> DbInserter<'a> {
challenges::description.eq(challenge.description.clone()),
challenges::rewards_total.eq(challenge.rewards_total),
challenges::fund_id.eq(challenge.fund_id),
challenges::challenge_url.eq(challenge.challenge_url.clone()),
);
diesel::insert_or_ignore_into(challenges::table)
.values(values)
Expand Down

0 comments on commit bae31f3

Please sign in to comment.