Skip to content

Commit e62e328

Browse files
authored
Merge pull request #110 from CodeGov-org/feat/review-vote
feat: add `vote` field to `ProposalReview`
2 parents ecb0bf0 + fbc5e66 commit e62e328

14 files changed

Lines changed: 160 additions & 4 deletions

File tree

src/backend/api/backend.did

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ type ProposalReviewStatus = variant {
208208
published;
209209
};
210210

211+
type ProposalVote = variant {
212+
unspecified;
213+
yes;
214+
no;
215+
};
216+
211217
type ProposalReview = record {
212218
proposal_id : text;
213219
user_id : text;
@@ -219,6 +225,7 @@ type ProposalReview = record {
219225
build_reproduced : opt bool;
220226
images_paths : vec text;
221227
proposal_review_commits : vec ProposalReviewCommitWithId;
228+
vote : ProposalVote;
222229
};
223230

224231
type ProposalReviewWithId = record {
@@ -231,6 +238,7 @@ type CreateProposalReviewRequest = record {
231238
summary : opt text;
232239
review_duration_mins : opt nat16;
233240
build_reproduced : opt bool;
241+
vote : opt ProposalVote;
234242
};
235243

236244
type CreateProposalReviewResponse = variant {
@@ -244,6 +252,7 @@ type UpdateProposalReviewRequest = record {
244252
summary : opt text;
245253
review_duration_mins : opt nat16;
246254
build_reproduced : opt bool;
255+
vote : opt ProposalVote;
247256
};
248257

249258
type UpdateProposalReviewResponse = variant {

src/backend/api/src/proposal_review.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ pub enum ProposalReviewStatus {
1010
Published,
1111
}
1212

13+
#[derive(Debug, CandidType, Deserialize, Clone, PartialEq, Eq)]
14+
pub enum ProposalVote {
15+
#[serde(rename = "unspecified")]
16+
Unspecified,
17+
#[serde(rename = "yes")]
18+
Yes,
19+
#[serde(rename = "no")]
20+
No,
21+
}
22+
1323
#[derive(Debug, CandidType, Deserialize, Clone, PartialEq, Eq)]
1424
pub struct ProposalReview {
1525
pub proposal_id: String,
@@ -22,6 +32,7 @@ pub struct ProposalReview {
2232
pub build_reproduced: Option<bool>,
2333
pub images_paths: Vec<String>,
2434
pub proposal_review_commits: Vec<ProposalReviewCommitWithId>,
35+
pub vote: ProposalVote,
2536
}
2637

2738
#[derive(Debug, Clone, CandidType, Deserialize, PartialEq, Eq)]
@@ -36,6 +47,7 @@ pub struct CreateProposalReviewRequest {
3647
pub summary: Option<String>,
3748
pub review_duration_mins: Option<u16>,
3849
pub build_reproduced: Option<bool>,
50+
pub vote: Option<ProposalVote>,
3951
}
4052

4153
pub type CreateProposalReviewResponse = ProposalReviewWithId;
@@ -47,6 +59,7 @@ pub struct UpdateProposalReviewRequest {
4759
pub summary: Option<String>,
4860
pub review_duration_mins: Option<u16>,
4961
pub build_reproduced: Option<bool>,
62+
pub vote: Option<ProposalVote>,
5063
}
5164

5265
#[derive(Debug, Clone, CandidType, Deserialize, PartialEq, Eq)]

src/backend/impl/src/controllers/proposal_review_controller.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ mod tests {
219219
fixtures,
220220
services::{MockAccessControlService, MockProposalReviewService},
221221
};
222+
use backend_api::ProposalVote;
222223
use mockall::predicate::*;
223224
use rstest::*;
224225

@@ -230,6 +231,7 @@ mod tests {
230231
summary: Some("summary".to_string()),
231232
review_duration_mins: Some(10),
232233
build_reproduced: Some(true),
234+
vote: Some(ProposalVote::Yes),
233235
};
234236
let response = CreateProposalReviewResponse {
235237
id: "id".to_string(),
@@ -272,6 +274,7 @@ mod tests {
272274
summary: Some("summary".to_string()),
273275
review_duration_mins: Some(10),
274276
build_reproduced: Some(true),
277+
vote: Some(ProposalVote::No),
275278
};
276279
let error = ApiError::permission_denied(&format!(
277280
"Principal {} must be a reviewer to call this endpoint",
@@ -312,6 +315,7 @@ mod tests {
312315
summary: Some("summary".to_string()),
313316
review_duration_mins: Some(10),
314317
build_reproduced: Some(true),
318+
vote: Some(ProposalVote::Yes),
315319
};
316320

317321
let mut access_control_service_mock = MockAccessControlService::new();
@@ -347,6 +351,7 @@ mod tests {
347351
summary: Some("summary".to_string()),
348352
review_duration_mins: Some(10),
349353
build_reproduced: Some(true),
354+
vote: None,
350355
};
351356
let error = ApiError::permission_denied(&format!(
352357
"Principal {} must be a reviewer to call this endpoint",

src/backend/impl/src/fixtures/proposal_review.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rstest::*;
22

3-
use crate::repositories::{ProposalReview, ProposalReviewStatus};
3+
use crate::repositories::{ProposalReview, ProposalReviewStatus, ProposalVote};
44

55
use super::{date_time_a, proposal_id, user_id, uuid};
66

@@ -16,6 +16,7 @@ pub fn proposal_review_draft() -> ProposalReview {
1616
review_duration_mins: Some(60),
1717
build_reproduced: Some(true),
1818
images_ids: vec![],
19+
vote: ProposalVote::Unspecified,
1920
}
2021
}
2122

@@ -31,6 +32,7 @@ pub fn proposal_review_published() -> ProposalReview {
3132
review_duration_mins: Some(60),
3233
build_reproduced: Some(true),
3334
images_ids: vec![uuid()],
35+
vote: ProposalVote::Yes,
3436
}
3537
}
3638

src/backend/impl/src/mappings/proposal_review.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::repositories::{
22
ProposalReview, ProposalReviewCommit, ProposalReviewCommitId, ProposalReviewId,
3-
ProposalReviewStatus,
3+
ProposalReviewStatus, ProposalVote,
44
};
55

66
use super::map_proposal_review_commits;
@@ -23,6 +23,26 @@ impl From<backend_api::ProposalReviewStatus> for ProposalReviewStatus {
2323
}
2424
}
2525

26+
impl From<backend_api::ProposalVote> for ProposalVote {
27+
fn from(vote: backend_api::ProposalVote) -> Self {
28+
match vote {
29+
backend_api::ProposalVote::Unspecified => ProposalVote::Unspecified,
30+
backend_api::ProposalVote::Yes => ProposalVote::Yes,
31+
backend_api::ProposalVote::No => ProposalVote::No,
32+
}
33+
}
34+
}
35+
36+
impl From<ProposalVote> for backend_api::ProposalVote {
37+
fn from(vote: ProposalVote) -> Self {
38+
match vote {
39+
ProposalVote::Unspecified => backend_api::ProposalVote::Unspecified,
40+
ProposalVote::Yes => backend_api::ProposalVote::Yes,
41+
ProposalVote::No => backend_api::ProposalVote::No,
42+
}
43+
}
44+
}
45+
2646
impl From<ProposalReview> for backend_api::ProposalReview {
2747
fn from(proposal_review: ProposalReview) -> Self {
2848
backend_api::ProposalReview {
@@ -36,6 +56,7 @@ impl From<ProposalReview> for backend_api::ProposalReview {
3656
build_reproduced: proposal_review.build_reproduced,
3757
images_paths: vec![],
3858
proposal_review_commits: vec![],
59+
vote: proposal_review.vote.into(),
3960
}
4061
}
4162
}

src/backend/impl/src/repositories/types/proposal_review.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ pub enum ProposalReviewStatus {
1717
Published,
1818
}
1919

20+
/// Same as `ic_nns_governance::pb::v1::Vote`.
21+
#[derive(Debug, CandidType, Deserialize, Clone, PartialEq, Eq)]
22+
#[repr(i32)]
23+
pub enum ProposalVote {
24+
Unspecified = 0,
25+
Yes = 1,
26+
No = 2,
27+
}
28+
2029
#[derive(Debug, CandidType, Deserialize, Clone, PartialEq, Eq)]
2130
pub struct ProposalReview {
2231
pub proposal_id: ProposalId,
@@ -28,6 +37,7 @@ pub struct ProposalReview {
2837
pub review_duration_mins: Option<u16>,
2938
pub build_reproduced: Option<bool>,
3039
pub images_ids: Vec<ImageId>,
40+
pub vote: ProposalVote,
3141
}
3242

3343
impl ProposalReview {

0 commit comments

Comments
 (0)