|
| 1 | +use diesel::{ExpressionMethods, Insertable}; |
1 | 2 | use serde::Deserialize;
|
2 | 3 | use std::convert::TryInto;
|
| 4 | +use vit_servicing_station_lib::db::models::challenges::{ |
| 5 | + Challenge as DbChallenge, ChallengeHighlights, |
| 6 | +}; |
3 | 7 | use vit_servicing_station_lib::db::models::community_advisors_reviews::{self, ReviewRanking};
|
4 | 8 | use vit_servicing_station_lib::db::models::proposals::{
|
5 | 9 | self, community_choice, simple, Category, ChallengeType, ProposalChallengeInfo, Proposer,
|
6 | 10 | };
|
7 | 11 | use vit_servicing_station_lib::db::models::vote_options::VoteOptions;
|
| 12 | +use vit_servicing_station_lib::db::schema::challenges; |
| 13 | + |
| 14 | +#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] |
| 15 | +pub struct Challenge { |
| 16 | + pub id: i32, |
| 17 | + #[serde(alias = "challengeType")] |
| 18 | + pub challenge_type: ChallengeType, |
| 19 | + pub title: String, |
| 20 | + pub description: String, |
| 21 | + #[serde(alias = "rewardsTotal")] |
| 22 | + pub rewards_total: i64, |
| 23 | + #[serde(alias = "proposersRewards")] |
| 24 | + pub proposers_rewards: i64, |
| 25 | + #[serde(alias = "fundId")] |
| 26 | + pub fund_id: i32, |
| 27 | + #[serde(alias = "challengeUrl")] |
| 28 | + pub challenge_url: String, |
| 29 | + pub highlights: Option<ChallengeHighlights>, |
| 30 | +} |
8 | 31 |
|
9 | 32 | #[derive(Deserialize, PartialEq, Eq, Debug, Clone)]
|
10 | 33 | pub struct Proposal {
|
@@ -104,6 +127,25 @@ fn default_challenge_id() -> i32 {
|
104 | 127 | -1
|
105 | 128 | }
|
106 | 129 |
|
| 130 | +impl Challenge { |
| 131 | + pub fn into_db_challenge_values( |
| 132 | + self, |
| 133 | + ) -> <DbChallenge as Insertable<challenges::table>>::Values { |
| 134 | + ( |
| 135 | + challenges::id.eq(self.id), |
| 136 | + challenges::challenge_type.eq(self.challenge_type.to_string()), |
| 137 | + challenges::title.eq(self.title), |
| 138 | + challenges::description.eq(self.description), |
| 139 | + challenges::rewards_total.eq(self.rewards_total), |
| 140 | + challenges::proposers_rewards.eq(self.proposers_rewards), |
| 141 | + challenges::fund_id.eq(self.fund_id), |
| 142 | + challenges::challenge_url.eq(self.challenge_url), |
| 143 | + // This should always be a valid json |
| 144 | + challenges::highlights.eq(serde_json::to_string(&self.highlights).ok()), |
| 145 | + ) |
| 146 | + } |
| 147 | +} |
| 148 | + |
107 | 149 | impl Proposal {
|
108 | 150 | pub fn into_db_proposal_and_challenge_info(
|
109 | 151 | self,
|
|
0 commit comments