feat: add message Tauri commands

This commit is contained in:
2026-08-12 17:21:44 +02:00
parent 7c2e5ca9a9
commit 3109ac4c22
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
use crate::models::Message;
use crate::state::{AppState, BASE_URL};
#[tauri::command]
pub async fn list_messages(
state: tauri::State<'_, AppState>,
conversation_id: String,
) -> Result<Vec<Message>, String> {
state
.client
.get(format!("{}/conversations/{}/messages", BASE_URL, conversation_id))
.send()
.await
.map_err(|e| e.to_string())?
.json()
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn send_message(
state: tauri::State<'_, AppState>,
conversation_id: String,
content: String,
) -> Result<Message, String> {
let user_id = state
.user_id
.lock()
.unwrap()
.clone()
.ok_or_else(|| "Not logged in".to_string())?;
let body = serde_json::json!({
"conversation_id": conversation_id,
"user_id": user_id,
"content": content,
});
state
.client
.post(format!("{}/messages", BASE_URL))
.json(&body)
.send()
.await
.map_err(|e| e.to_string())?
.json()
.await
.map_err(|e| e.to_string())
}

View File

@@ -1,3 +1,4 @@
pub mod conversation;
pub mod message;
pub mod user;
pub mod workspace;