Skip to content

Commit

Permalink
update db schema, and fixed webhook formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
manglemix committed Jan 28, 2025
1 parent 2446c22 commit 25b15a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*.log
.reset-db
*.sqlite
*.sqlite.backup
/config.json
/.env
15 changes: 9 additions & 6 deletions usr-backend/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn new_order(
Json(pending_order): Json<PendingOrder>,
) -> (StatusCode, &'static str) {
let webhook_msg = format!(
">>> **New Order!**\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
"**New Order!**\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
pending_order.name,
pending_order.vendor,
pending_order.link,
Expand All @@ -50,6 +50,7 @@ async fn new_order(
reason: ActiveValue::Set(pending_order.reason),
vendor: ActiveValue::Set(pending_order.vendor),
link: ActiveValue::Set(pending_order.link),
ref_number: ActiveValue::NotSet,
};
let result = state.db.transaction(|tx| Box::pin(async move {
let model = active_model.insert(tx).await?;
Expand Down Expand Up @@ -90,6 +91,7 @@ pub struct ChangeOrder {
pub reason: String,
pub vendor: String,
pub link: String,
pub ref_number: Option<u32>
}

#[axum::debug_handler]
Expand All @@ -112,7 +114,7 @@ async fn change_order(
}
}
let webhook_msg = format!(
">>> ***Order Changed***\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
"***Order Changed***\n**Name:** {}\n**Vendor:** {}\n**Link:** {}\n**Count:** {}\n**Unit Cost:** ${}\n**Subtotal:** ${}\n**Team:** {}\n**Reason:** {}",
change_order.name,
change_order.vendor,
change_order.link,
Expand All @@ -132,6 +134,7 @@ async fn change_order(
reason: ActiveValue::Set(change_order.reason),
vendor: ActiveValue::Set(change_order.vendor),
link: ActiveValue::Set(change_order.link),
ref_number: ActiveValue::Set(change_order.ref_number)
};
if let Err(e) = active_model.update(&state.db).await {
error!("Failed to change order: {e}");
Expand Down Expand Up @@ -189,7 +192,7 @@ async fn cancel_order(
}
};
webhook_msg = format!(
">>> ***Order Cancelled***\n**Name:** {}\n**Count:** {}\n**Team:** {}",
"***Order Cancelled***\n**Name:** {}\n**Count:** {}\n**Team:** {}",
model.name,
model.count,
model.team,
Expand Down Expand Up @@ -259,21 +262,21 @@ async fn update_order(
if update_order.status == order_status::Status::InStorage {
if model.store_in.is_empty() {
webhook_msg = format!(
">>> **Order Complete!**\n**Name:** {}\n**Team:** {}",
"**Order Complete!**\n**Name:** {}\n**Team:** {}",
model.name,
model.team
);
} else {
webhook_msg = format!(
">>> **Order Complete!**\n**Name:** {}\n**Team:** {}\n**Location:** {}",
"**Order Complete!**\n**Name:** {}\n**Team:** {}\n**Location:** {}",
model.name,
model.team,
model.store_in
);
}
} else {
webhook_msg = format!(
">>> **Order Update!**\n**Name:** {}\n**Team:** {}\n**Status:** {}",
"**Order Update!**\n**Name:** {}\n**Team:** {}\n**Status:** {}",
model.name,
model.team,
update_order.status
Expand Down
3 changes: 3 additions & 0 deletions usr-backend/src/manifest/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub struct Model {
pub reason: String,
pub vendor: String,
pub link: String,
#[sea_orm(nullable)]
#[serde(skip_serializing_if = "Option::is_none")]
pub ref_number: Option<u32>
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
5 changes: 3 additions & 2 deletions usr-backend/src/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl BatchedWebhook {
let replacement = HashMap::with_capacity(guard.queue.capacity());
queue = std::mem::replace(&mut guard.queue, replacement);
}
let mut running = String::new();
let mut running = String::from(">>> ");
for (_, msg) in queue {
if running.len() + msg.len() + 1 < 2000 {
running.push_str(&msg);
Expand All @@ -48,7 +48,8 @@ impl BatchedWebhook {
{
error!("Failed to trigger webhook: {e}");
}
running = msg;
running = String::from(">>> ");
running.push_str(&msg);
}
}
if let Err(e) = self.discord
Expand Down

0 comments on commit 25b15a3

Please sign in to comment.