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())
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
43
src-tauri/src/models.rs
Normal file
43
src-tauri/src/models.rs
Normal file
@@ -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<String>,
|
||||
pub bio: Option<String>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
pub kind: String,
|
||||
pub name: Option<String>,
|
||||
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,
|
||||
}
|
||||
19
src-tauri/src/state.rs
Normal file
19
src-tauri/src/state.rs
Normal file
@@ -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<Option<String>>,
|
||||
pub user_id: Mutex<Option<String>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
client: reqwest::Client::new(),
|
||||
token: Mutex::new(None),
|
||||
user_id: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user