1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use crate::api::token;
use crate::email;
use actix_web::web;
use actix_web::{
get, post,
web::{Data, Json},
HttpResponse,
};
use common::models::status_report;
use common::models::types::TeamResponse;
use config::Config;
use database::repository::db_connector::Database;
use log::debug;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EmailInfo {
pub email: String,
pub name: String,
}
#[get("/sprints")]
pub async fn get_sprints(_data: Data<(Database, Config, Config)>) -> HttpResponse {
HttpResponse::NotImplemented().body("Not Ready")
}
#[post("/submit/team")]
pub async fn post_team(
data: Data<(Database, Config, Config)>,
body: web::Json<TeamResponse>,
) -> HttpResponse {
let completion_value;
if body.completion_percent.is_empty() {
debug!("Bad Request: completion_percent is empty");
completion_value = 0;
} else {
completion_value = match body.completion_percent.parse() {
Ok(value) => value,
Err(error_message) => {
debug!(
"Bad Request: completion_percent is unable to be parse ({}) ({})",
body.completion_percent, error_message
);
return HttpResponse::BadRequest().body("completion_percent is unable to be parse");
}
}
}
let update_value = status_report::TeamReport {
teams: "eagles".to_string(), sprint_num: 1,
understand_easiest: body.understand_easy.clone(),
understand_hardest: body.understand_hard.clone(),
approach_easiest: body.approach_easy.clone(),
approach_hardest: body.approach_hard.clone(),
solve_easiest: body.solve_easy.clone(),
solve_hardest: body.solve_hard.clone(),
evaluate_easiest: body.evaluate_easy.clone(),
evaluate_hardest: body.evaluate_hard.clone(),
completion: completion_value,
contact: "student@ewu.edu".to_string(), comments: body.issues_comments.clone(),
};
data.get_ref().0.update_team_report(update_value.clone());
let email_out = email::team::send_confirmation_email(
"Not Stu <nelof50340@soremap.com>".to_string(),
update_value,
&data.get_ref().2,
&data.get_ref().1,
);
match email_out {
Ok(message) => HttpResponse::Ok().body(format!("Done (Confirmation {})", message)),
Err(message) => {
HttpResponse::InternalServerError().body(format!("Done (Error {})", message))
}
}
}
#[get("/send_test_email")]
pub async fn send_email(data: Data<(Database, Config, Config)>) -> HttpResponse {
let email_out = email::test::send_test_email(
format!(
"admin <{}>",
data.get_ref()
.1
.get::<String>("admin_email")
.expect("Missing admin email")
),
&data.get_ref().2,
&data.get_ref().1,
);
match email_out {
Ok(message) => HttpResponse::Ok().body(message),
Err(message) => HttpResponse::InternalServerError().body(message),
}
}
#[post("/send_test_email")]
pub async fn send_email_to(
data: Data<(Database, Config, Config)>,
email_info: Json<EmailInfo>,
) -> HttpResponse {
let email_out = email::test::send_test_email(
format!("{} <{}>", email_info.name, email_info.email),
&data.get_ref().2,
&data.get_ref().1,
);
match email_out {
Ok(message) => HttpResponse::Ok().body(message),
Err(message) => HttpResponse::InternalServerError().body(message),
}
}
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/api")
.configure(token::config)
.service(send_email) .service(send_email_to) .service(get_sprints)
.service(post_team),
);
}