This commit is contained in:
@@ -297,17 +297,14 @@ pub async fn send_message(
|
||||
|
||||
match statement.exists(params![user_id, payload.conv_id]) {
|
||||
Ok(true) => {
|
||||
// user is part of the conversation — continue
|
||||
}
|
||||
Ok(false) => {
|
||||
// early exit: not part of the conversation
|
||||
return (
|
||||
StatusCode::FORBIDDEN,
|
||||
"Not part of the conversation".to_string(),
|
||||
);
|
||||
}
|
||||
Err(_) => {
|
||||
// query failed
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Query failed".to_string(),
|
||||
@@ -330,10 +327,6 @@ pub async fn send_message(
|
||||
);
|
||||
}
|
||||
};
|
||||
//let message_id = conn.last_insert_rowid();
|
||||
// FIXME: add sent_at and message id in the response.
|
||||
|
||||
// --- send to conversation participants ---
|
||||
let mut stmt_participants = conn
|
||||
.prepare("SELECT user_id FROM conversation_participants WHERE conversation_id = ?1")
|
||||
.expect("prepare participants failed");
|
||||
@@ -370,7 +363,6 @@ pub async fn send_message(
|
||||
),
|
||||
)
|
||||
}
|
||||
//Ok(_) => (StatusCode::NOT_FOUND, "Conversation not found".to_string()),
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Message {
|
||||
@@ -514,7 +506,6 @@ struct Conversation {
|
||||
title: String,
|
||||
}
|
||||
|
||||
//FIXME: allow null conv name ? default to persons name
|
||||
pub async fn get_convs(
|
||||
State(state): State<AppState>,
|
||||
//Path((item_name, item_amount)): Path<(String, i32)>,
|
||||
@@ -553,7 +544,6 @@ pub async fn get_convs(
|
||||
})
|
||||
}) {
|
||||
Ok(rows) => rows,
|
||||
//Ok(_) => {}, IMPLEMENT NO CONV ?
|
||||
Err(e) => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -571,9 +561,6 @@ pub async fn get_convs(
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json("error".to_string())));
|
||||
|
||||
match serde_json::to_string(&convs) {
|
||||
Ok(json) => (StatusCode::OK, json),
|
||||
Err(e) => (
|
||||
@@ -582,69 +569,3 @@ pub async fn get_convs(
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub async fn get_convs(
|
||||
State(state): State<AppState>,
|
||||
//Path((item_name, item_amount)): Path<(String, i32)>,
|
||||
AuthClaims{ user_id, hotel_id}: AuthClaims,
|
||||
) -> impl IntoResponse {
|
||||
|
||||
let pool = state.hotel_pools.get_pool(hotel_id);
|
||||
|
||||
let conn = match pool.get(){
|
||||
Ok(conn) => conn,
|
||||
Err(err) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("Pool error: {}", err).into_response() )
|
||||
|
||||
};
|
||||
|
||||
let mut stmt = match conn.prepare(
|
||||
"SELECT id, title FROM conversation WHERE creator_id = ?1",
|
||||
) {
|
||||
Ok(s) => s,
|
||||
Err(e) =>
|
||||
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, format!("Prepare failed: {}", e).into_response() )
|
||||
|
||||
|
||||
};
|
||||
|
||||
let rows = match stmt.query_map(params![user_id], |row| {
|
||||
let id: i32 = row.get(0)?;
|
||||
let title: String = row.get(1)?;
|
||||
Ok((title, id))
|
||||
}) {
|
||||
Ok(rows) => rows,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("Query failed: {}", e).into_response() )
|
||||
|
||||
};
|
||||
|
||||
|
||||
let mut map = HashMap::new();
|
||||
|
||||
// ✅ Iterate through the row results
|
||||
for row_result in rows {
|
||||
match row_result {
|
||||
Ok((title, id)) => {
|
||||
map.insert(title, id);
|
||||
}
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("Row parsing failed: {}", e).into_response() )
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let conv_map_json = match to_value(map) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("List unwrapping failed: {}", e).into_response() )
|
||||
};
|
||||
|
||||
let conv_map_clean_json = serde_json::to_value(map)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Serialization failed: {}", e).into_response() ));
|
||||
|
||||
|
||||
|
||||
(StatusCode::OK, Json(conv_map_clean_json)).into_response()
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user