Skip to main content

snipt_server/api/
models.rs

1//! Data models for API requests and responses.
2
3use serde::{Deserialize, Serialize};
4
5/// Standard API response format
6#[derive(Serialize, Deserialize)]
7pub struct ApiResponse<T> {
8    pub success: bool,
9    pub data: Option<T>,
10    pub error: Option<String>,
11}
12
13impl<T> ApiResponse<T> {
14    pub fn success(data: T) -> Self {
15        Self {
16            success: true,
17            data: Some(data),
18            error: None,
19        }
20    }
21
22    pub fn error(message: String) -> Self {
23        Self {
24            success: false,
25            data: None,
26            error: Some(message),
27        }
28    }
29}
30
31/// Daemon status information
32#[derive(Serialize, Deserialize)]
33pub struct DaemonStatus {
34    pub running: bool,
35    pub pid: Option<u32>,
36    pub config_path: String,
37    pub api_server: ApiServerInfo,
38}
39
40/// API server information
41#[derive(Serialize, Deserialize)]
42pub struct ApiServerInfo {
43    pub port: u16,
44    pub url: String,
45}
46
47/// Request model for adding or updating a snippet
48#[derive(Deserialize)]
49pub struct SnippetRequest {
50    pub shortcut: String,
51    pub snippet: String,
52}
53
54/// Request model for retrieving a single snippet
55#[derive(Deserialize)]
56pub struct GetSnippetRequest {
57    pub shortcut: String,
58}
59
60/// Request model for deleting a snippet
61#[derive(Deserialize)]
62pub struct DeleteSnippetRequest {
63    pub shortcut: String,
64}