| 1 | use sqlx::{PgPool, Row};
|
|---|
| 2 | use tauri::State;
|
|---|
| 3 |
|
|---|
| 4 | #[tauri::command]
|
|---|
| 5 | pub async fn get_kitchen_orders(
|
|---|
| 6 | pool: State<'_, PgPool>
|
|---|
| 7 | ) -> Result<Vec<serde_json::Value>, String> {
|
|---|
| 8 | let rows = sqlx::query(
|
|---|
| 9 | r#"
|
|---|
| 10 | SELECT
|
|---|
| 11 | o.order_id,
|
|---|
| 12 | o.table_id,
|
|---|
| 13 | rt.table_number,
|
|---|
| 14 | oi.item_number,
|
|---|
| 15 | p.name AS product_name,
|
|---|
| 16 | oi.quantity,
|
|---|
| 17 | o.created_at
|
|---|
| 18 | FROM orders o
|
|---|
| 19 | JOIN order_item oi ON o.order_id = oi.order_id
|
|---|
| 20 | JOIN product p ON oi.product_id = p.product_id
|
|---|
| 21 | JOIN restaurant_table rt ON o.table_id = rt.table_id
|
|---|
| 22 | WHERE o.status = 'АКТИВНА'
|
|---|
| 23 | ORDER BY o.created_at ASC, oi.item_number ASC
|
|---|
| 24 | "#
|
|---|
| 25 | )
|
|---|
| 26 | .fetch_all(pool.inner())
|
|---|
| 27 | .await
|
|---|
| 28 | .map_err(|e| e.to_string())?;
|
|---|
| 29 |
|
|---|
| 30 | let mut result = Vec::new();
|
|---|
| 31 | for row in rows {
|
|---|
| 32 | result.push(serde_json::json!({
|
|---|
| 33 | "order_id": row.get::<i32, _>("order_id"),
|
|---|
| 34 | "table_id": row.get::<i32, _>("table_id"),
|
|---|
| 35 | "table_number": row.get::<String, _>("table_number"),
|
|---|
| 36 | "item_number": row.get::<i32, _>("item_number"),
|
|---|
| 37 | "product_name": row.get::<String, _>("product_name"),
|
|---|
| 38 | "quantity": row.get::<i32, _>("quantity"),
|
|---|
| 39 | "created_at": row.get::<chrono::DateTime<chrono::Utc>, _>("created_at").to_rfc3339()
|
|---|
| 40 | }));
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | Ok(result)
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | #[tauri::command]
|
|---|
| 47 | pub async fn mark_kitchen_order_ready(
|
|---|
| 48 | order_id: i32,
|
|---|
| 49 | pool: State<'_, PgPool>
|
|---|
| 50 | ) -> Result<(), String> {
|
|---|
| 51 | println!("Нарачката {} е означена како спремна во кујна.", order_id);
|
|---|
| 52 | Ok(())
|
|---|
| 53 | } |
|---|