|
1 |
| -use diesel::expression::dsl::*; |
2 | 1 | use diesel::prelude::*;
|
3 |
| -use diesel::select; |
4 |
| -use diesel::types::VarChar; |
5 | 2 |
|
6 | 3 | use DB_POOL;
|
7 |
| -use domain::github::{GitHubUser, Issue}; |
| 4 | +use domain::github::{GitHubUser, Issue, IssueComment}; |
8 | 5 | use domain::rfcbot::{FcpProposal, FcpReviewRequest};
|
9 | 6 | use error::DashResult;
|
10 | 7 |
|
11 |
| -pub fn all_team_members() -> DashResult<Vec<String>> { |
12 |
| - let conn = try!(DB_POOL.get()); |
| 8 | +#[derive(Serialize)] |
| 9 | +pub struct FcpWithInfo { |
| 10 | + fcp: FcpProposal, |
| 11 | + reviews: Vec<(GitHubUser, bool)>, |
| 12 | + issue: Issue, |
| 13 | + status_comment: IssueComment, |
| 14 | +} |
| 15 | + |
| 16 | +pub fn all_fcps() -> DashResult<Vec<FcpWithInfo>> { |
| 17 | + use domain::schema::{fcp_proposal, fcp_review_request, githubuser, issue, issuecomment}; |
| 18 | + |
| 19 | + let conn = &*DB_POOL.get()?; |
| 20 | + |
| 21 | + let proposals = fcp_proposal::table.filter(fcp_proposal::fcp_start.is_null()) |
| 22 | + .load::<FcpProposal>(conn)?; |
| 23 | + |
| 24 | + let mut all_fcps = Vec::new(); |
| 25 | + |
| 26 | + for fcp in proposals { |
| 27 | + let reviews = fcp_review_request::table.filter(fcp_review_request::fk_proposal.eq(fcp.id)) |
| 28 | + .load::<FcpReviewRequest>(conn)?; |
13 | 29 |
|
14 |
| - // waiting on associations to get this into proper typed queries |
| 30 | + let mut reviews_with_users = Vec::new(); |
| 31 | + |
| 32 | + for review in reviews { |
| 33 | + let user = githubuser::table.filter(githubuser::id.eq(review.fk_reviewer)).first(conn)?; |
| 34 | + reviews_with_users.push((user, review.reviewed)); |
| 35 | + } |
| 36 | + |
| 37 | + let status_comment = |
| 38 | + issuecomment::table.filter(issuecomment::id.eq(fcp.fk_bot_tracking_comment)) |
| 39 | + .first::<IssueComment>(conn)?; |
| 40 | + |
| 41 | + let issue = issue::table.filter(issue::id.eq(fcp.fk_issue)).first::<Issue>(conn)?; |
| 42 | + |
| 43 | + let fcp_with_info = FcpWithInfo { |
| 44 | + fcp: fcp, |
| 45 | + reviews: reviews_with_users, |
| 46 | + issue: issue, |
| 47 | + status_comment: status_comment, |
| 48 | + }; |
| 49 | + |
| 50 | + all_fcps.push(fcp_with_info); |
| 51 | + } |
15 | 52 |
|
16 |
| - Ok(try!(select(sql::<VarChar>("\ |
17 |
| - DISTINCT u.login \ |
18 |
| - FROM githubuser u, memberships m \ |
19 |
| - WHERE u.id = m.fk_member \ |
20 |
| - ORDER BY u.login")) |
21 |
| - .load(&*conn))) |
| 53 | + Ok(all_fcps) |
22 | 54 | }
|
23 | 55 |
|
24 | 56 | #[derive(Queryable, Serialize)]
|
|
0 commit comments