From 55133751cb5cb2873dc0fc708674a63d99ab7838 Mon Sep 17 00:00:00 2001 From: MDietermann Date: Wed, 12 Aug 2026 16:56:03 +0200 Subject: [PATCH] feat: add AppState and domain models - Introduce state.rs with AppState (HTTP client + token/user_id state) - Define core models in models.rs (User, Workspace, Conversation, Message, AuthTokenResponse) - Integrate state management into lib.rs via .manage(AppState::new()) --- src-tauri/src/lib.rs | 6 ++++++ src-tauri/src/models.rs | 43 +++++++++++++++++++++++++++++++++++++++++ src-tauri/src/state.rs | 19 ++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src-tauri/src/models.rs create mode 100644 src-tauri/src/state.rs diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0d94ef8..9efa19b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,5 +1,11 @@ +mod models; +mod state; + +use state::AppState; + pub fn run() { tauri::Builder::default() + .manage(AppState::new()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/models.rs b/src-tauri/src/models.rs new file mode 100644 index 0000000..54da136 --- /dev/null +++ b/src-tauri/src/models.rs @@ -0,0 +1,43 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone)] +pub struct User { + pub id: String, + pub email: String, + pub username: String, + pub display_name: String, + pub avatar_url: Option, + pub bio: Option, +} + +#[derive(Serialize, Deserialize)] +pub struct Workspace { + pub id: String, + pub name: String, + pub slug: String, + pub owner_id: String, +} + +#[derive(Serialize, Deserialize)] +pub struct Conversation { + pub id: String, + pub workspace_id: Option, + pub kind: String, + pub name: Option, + pub is_public: bool, + pub created_by: String, +} + +#[derive(Serialize, Deserialize)] +pub struct Message { + pub id: String, + pub conversation_id: String, + pub user_id: String, + pub content: String, + pub created_at: String, +} + +#[derive(Deserialize)] +pub struct AuthTokenResponse { + pub token: String, +} diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs new file mode 100644 index 0000000..4eebae3 --- /dev/null +++ b/src-tauri/src/state.rs @@ -0,0 +1,19 @@ +use std::sync::Mutex; + +pub const BASE_URL: &str = "http://localhost:3000/api/v1"; + +pub struct AppState { + pub client: reqwest::Client, + pub token: Mutex>, + pub user_id: Mutex>, +} + +impl AppState { + pub fn new() -> Self { + Self { + client: reqwest::Client::new(), + token: Mutex::new(None), + user_id: Mutex::new(None), + } + } +}