some fixes, first push to ovh, discord webhook
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
use argon2::Params;
|
||||
use axum::{extract::{ws::{close_code::STATUS, Message}, Path, State}, http::StatusCode, response::IntoResponse};
|
||||
use rusqlite::params;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
|
||||
|
||||
@@ -33,6 +34,14 @@ pub async fn create_inventory_item(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct InventoryItems {
|
||||
id: i32,
|
||||
amount: i32,
|
||||
name: String,
|
||||
user_id: i32,
|
||||
updated_at: String,
|
||||
}
|
||||
|
||||
pub async fn update_inventory_item(
|
||||
State(state): State<AppState>,
|
||||
@@ -81,4 +90,48 @@ pub async fn update_inventory_item(
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_inventory_item(
|
||||
State(state): State<AppState>,
|
||||
AuthClaims { user_id, hotel_id }: AuthClaims,
|
||||
) -> impl IntoResponse {
|
||||
let pool = state.hotel_pools.get_pool(hotel_id);
|
||||
|
||||
let conn = match pool.get() {
|
||||
Ok(c) => c,
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Pool error".to_string()),
|
||||
};
|
||||
|
||||
let mut stmt = match conn.prepare("SELECT id, amount, item_name, user_id FROM inventory") {
|
||||
Ok(s) => s,
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Statement error".to_string()),
|
||||
};
|
||||
|
||||
let mut query_result = match stmt.query([]) {
|
||||
Ok(r) => r,
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Query error".to_string()),
|
||||
};
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
||||
while let Ok(Some(row)) = query_result.next() {
|
||||
let item = InventoryItems {
|
||||
id: row.get("id").unwrap_or_default(),
|
||||
amount: row.get("amount").unwrap_or_default(),
|
||||
name: row.get("name").unwrap_or_default(),
|
||||
user_id: row.get("user_id").unwrap_or_default(),
|
||||
updated_at: row.get("updated_at").unwrap_or_default(),
|
||||
};
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
// Serialize to JSON
|
||||
let json = match serde_json::to_string(&items) {
|
||||
Ok(j) => j,
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Serialization error".to_string()),
|
||||
};
|
||||
|
||||
(StatusCode::OK, json)
|
||||
}
|
||||
@@ -10,4 +10,5 @@ pub fn inventory_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/update_item/{item_id}/{item_amount}", put(update_inventory_item))
|
||||
.route("/add_item/{item_name}/{item_amount}", post(create_inventory_item))
|
||||
.route("/get_item/", get(get_inventory_item))
|
||||
}
|
||||
Reference in New Issue
Block a user