Skip to content

Commit 9026ee5

Browse files
committed
refactor(api): add ApiKey extractor in ticket_create external handler
1 parent d776b2e commit 9026ee5

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

  • rustmail/src/api/handler/externals/tickets

rustmail/src/api/handler/externals/tickets/create.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
use crate::db::repr::{ApiKey, Permission};
2+
use crate::prelude::api::*;
13
use crate::types::BotState;
24
use axum::Json;
3-
use axum::extract::State;
5+
use axum::extract::{Extension, State};
46
use axum::http::StatusCode;
57
use rustmail_types::CreateTicket;
68
use std::sync::Arc;
79
use tokio::sync::Mutex;
810

911
pub async fn handle_external_ticket_create(
12+
Extension(api_key): Extension<ApiKey>,
1013
State(bot_state): State<Arc<Mutex<BotState>>>,
1114
Json(update): Json<CreateTicket>,
1215
) -> Result<Json<serde_json::Value>, (StatusCode, String)> {
13-
let current_config = {
16+
check_permission(&api_key, Permission::CreateTicket)
17+
.map_err(|e| (StatusCode::FORBIDDEN, format!("{:?}", e)))?;
18+
19+
let _current_config = {
1420
let state = bot_state.lock().await;
1521
match &state.config {
1622
Some(c) => c.clone(),
@@ -24,9 +30,12 @@ pub async fn handle_external_ticket_create(
2430
};
2531

2632
println!(
27-
"Discor ID : {:?} | Api key: {:?}",
28-
update.discord_id, update.api_key
33+
"API Key #{} creating ticket for Discord ID: {:?}",
34+
api_key.id, update.discord_id
2935
);
3036

31-
Ok(Json(serde_json::json!({"status": "ticket created"})))
37+
Ok(Json(serde_json::json!({
38+
"status": "ticket created",
39+
"message": "Ticket creation endpoint - implementation pending"
40+
})))
3241
}

0 commit comments

Comments
 (0)