Skip to content

Commit 25b15a3

Browse files
committed
update db schema, and fixed webhook formatting
1 parent 2446c22 commit 25b15a3

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*.log
44
.reset-db
55
*.sqlite
6+
*.sqlite.backup
67
/config.json
78
/.env

usr-backend/src/manifest.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async fn new_order(
3030
Json(pending_order): Json<PendingOrder>,
3131
) -> (StatusCode, &'static str) {
3232
let webhook_msg = format!(
33-
">>> **New Order!**\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
33+
"**New Order!**\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
3434
pending_order.name,
3535
pending_order.vendor,
3636
pending_order.link,
@@ -50,6 +50,7 @@ async fn new_order(
5050
reason: ActiveValue::Set(pending_order.reason),
5151
vendor: ActiveValue::Set(pending_order.vendor),
5252
link: ActiveValue::Set(pending_order.link),
53+
ref_number: ActiveValue::NotSet,
5354
};
5455
let result = state.db.transaction(|tx| Box::pin(async move {
5556
let model = active_model.insert(tx).await?;
@@ -90,6 +91,7 @@ pub struct ChangeOrder {
9091
pub reason: String,
9192
pub vendor: String,
9293
pub link: String,
94+
pub ref_number: Option<u32>
9395
}
9496

9597
#[axum::debug_handler]
@@ -112,7 +114,7 @@ async fn change_order(
112114
}
113115
}
114116
let webhook_msg = format!(
115-
">>> ***Order Changed***\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
117+
"***Order Changed***\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
116118
change_order.name,
117119
change_order.vendor,
118120
change_order.link,
@@ -132,6 +134,7 @@ async fn change_order(
132134
reason: ActiveValue::Set(change_order.reason),
133135
vendor: ActiveValue::Set(change_order.vendor),
134136
link: ActiveValue::Set(change_order.link),
137+
ref_number: ActiveValue::Set(change_order.ref_number)
135138
};
136139
if let Err(e) = active_model.update(&state.db).await {
137140
error!("Failed to change order: {e}");
@@ -189,7 +192,7 @@ async fn cancel_order(
189192
}
190193
};
191194
webhook_msg = format!(
192-
">>> ***Order Cancelled***\n**Name:** {}\n**Count:** {}\n**Team:** {}",
195+
"***Order Cancelled***\n**Name:** {}\n**Count:** {}\n**Team:** {}",
193196
model.name,
194197
model.count,
195198
model.team,
@@ -259,21 +262,21 @@ async fn update_order(
259262
if update_order.status == order_status::Status::InStorage {
260263
if model.store_in.is_empty() {
261264
webhook_msg = format!(
262-
">>> **Order Complete!**\n**Name:** {}\n**Team:** {}",
265+
"**Order Complete!**\n**Name:** {}\n**Team:** {}",
263266
model.name,
264267
model.team
265268
);
266269
} else {
267270
webhook_msg = format!(
268-
">>> **Order Complete!**\n**Name:** {}\n**Team:** {}\n**Location:** {}",
271+
"**Order Complete!**\n**Name:** {}\n**Team:** {}\n**Location:** {}",
269272
model.name,
270273
model.team,
271274
model.store_in
272275
);
273276
}
274277
} else {
275278
webhook_msg = format!(
276-
">>> **Order Update!**\n**Name:** {}\n**Team:** {}\n**Status:** {}",
279+
"**Order Update!**\n**Name:** {}\n**Team:** {}\n**Status:** {}",
277280
model.name,
278281
model.team,
279282
update_order.status

usr-backend/src/manifest/order.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub struct Model {
1616
pub reason: String,
1717
pub vendor: String,
1818
pub link: String,
19+
#[sea_orm(nullable)]
20+
#[serde(skip_serializing_if = "Option::is_none")]
21+
pub ref_number: Option<u32>
1922
}
2023

2124
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

usr-backend/src/webhook.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl BatchedWebhook {
3636
let replacement = HashMap::with_capacity(guard.queue.capacity());
3737
queue = std::mem::replace(&mut guard.queue, replacement);
3838
}
39-
let mut running = String::new();
39+
let mut running = String::from(">>> ");
4040
for (_, msg) in queue {
4141
if running.len() + msg.len() + 1 < 2000 {
4242
running.push_str(&msg);
@@ -48,7 +48,8 @@ impl BatchedWebhook {
4848
{
4949
error!("Failed to trigger webhook: {e}");
5050
}
51-
running = msg;
51+
running = String::from(">>> ");
52+
running.push_str(&msg);
5253
}
5354
}
5455
if let Err(e) = self.discord

0 commit comments

Comments
 (0)