Skip to content

Commit c2a4b66

Browse files
committed
backend: Update chargelog templates and route
1 parent 1ce797c commit c2a4b66

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

backend/src/routes/send_chargelog_to_user.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct SendChargelogMetadata {
2020
pub user_uuid: String,
2121
pub filename: String,
2222
pub display_name: String,
23+
pub monthly_send: bool,
2324
}
2425

2526
#[derive(ToSchema, MultipartForm)]
@@ -37,6 +38,7 @@ struct ChargelogDETemplate<'a> {
3738
month: &'a str,
3839
filename: &'a str,
3940
display_name: &'a str,
41+
monthly_send: bool,
4042
}
4143

4244
#[derive(Template)]
@@ -46,6 +48,7 @@ struct ChargelogENTemplate<'a> {
4648
month: &'a str,
4749
filename: &'a str,
4850
display_name: &'a str,
51+
monthly_send: bool,
4952
}
5053

5154
fn render_chargelog_email(
@@ -54,6 +57,7 @@ fn render_chargelog_email(
5457
filename: &str,
5558
display_name: &str,
5659
lang: &str,
60+
monthly_send: bool,
5761
) -> actix_web::Result<(String, String)> {
5862
let (body, subject) = match lang {
5963
"de" | "de-DE" => {
@@ -62,12 +66,17 @@ fn render_chargelog_email(
6266
month,
6367
filename,
6468
display_name,
69+
monthly_send,
6570
};
6671
match template.render() {
67-
Ok(b) => (
68-
b,
69-
format!("Dein Ladelog für {} von {}", month, display_name),
70-
),
72+
Ok(b) => {
73+
let subject = if monthly_send {
74+
format!("Dein Ladelog für {} von {}", month, display_name)
75+
} else {
76+
format!("Dein Ladelog von {}", display_name)
77+
};
78+
(b, subject)
79+
},
7180
Err(e) => {
7281
log::error!(
7382
"Failed to render German chargelog email template for user '{}': {}",
@@ -84,12 +93,17 @@ fn render_chargelog_email(
8493
month,
8594
filename,
8695
display_name,
96+
monthly_send,
8797
};
8898
match template.render() {
89-
Ok(b) => (
90-
b,
91-
format!("Your Charge Log for {} from {}", month, display_name),
92-
),
99+
Ok(b) => {
100+
let subject = if monthly_send {
101+
format!("Your Charge Log for {} from {}", month, display_name)
102+
} else {
103+
format!("Your Charge Log from {}", display_name)
104+
};
105+
(b, subject)
106+
},
93107
Err(e) => {
94108
log::error!(
95109
"Failed to render English chargelog email template for user '{}': {}",
@@ -158,6 +172,7 @@ pub async fn send_chargelog(
158172
&metadata.filename,
159173
&metadata.display_name,
160174
&lang_str,
175+
metadata.monthly_send,
161176
)?;
162177

163178
let mut chargelog_file = chargelog.file.reopen().map_err(|err| {
@@ -238,7 +253,8 @@ mod tests {
238253
.unwrap()
239254
.to_string(),
240255
"display_name": "Test Device",
241-
"filename": "chargelog.pdf"
256+
"filename": "chargelog.pdf",
257+
"monthly_send": true
242258
});
243259

244260
let boundary = "----testboundary";
@@ -273,7 +289,8 @@ mod tests {
273289
.unwrap()
274290
.to_string(),
275291
"display_name": "Test Device",
276-
"filename": "chargelog.pdf"
292+
"filename": "chargelog.pdf",
293+
"monthly_send": false
277294
});
278295

279296
let boundary = "----testboundary2";

backend/templates/chargelog_de.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
</head>
55
<body>
66
<h3>Hallo {{name}},</h3>
7+
{% if monthly_send %}
78
<p>Anbei findest du das Ladelog von deinem Gerät "{{display_name}}" für den Monat {{month}}.</p>
9+
{% else %}
10+
<p>Anbei findest du das Ladelog von deinem Gerät "{{display_name}}".</p>
11+
{% endif %}
812
<p>Die Datei ist als Anhang dieser E-Mail beigefügt: {{filename}}</p>
913
</body>
1014
</html>

backend/templates/chargelog_en.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
</head>
55
<body>
66
<h3>Hello {{name}},</h3>
7+
{% if monthly_send %}
78
<p>Please find attached the charge log from your device "{{display_name}}" for the month of {{month}}.</p>
9+
{% else %}
10+
<p>Please find attached the charge log from your device "{{display_name}}".</p>
11+
{% endif %}
812
<p>The file is attached to this email: {{filename}}</p>
913
</body>
1014
</html>

0 commit comments

Comments
 (0)