romm_api/endpoints/
device.rs1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use super::Endpoint;
7
8#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
10#[serde(rename_all = "snake_case")]
11pub enum SyncMode {
12 Api,
13 FileTransfer,
14 PushPull,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct DeviceCreateResponse {
20 pub device_id: String,
21 pub name: Option<String>,
22 pub created_at: String,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct DeviceSchema {
28 pub id: String,
29 pub user_id: u64,
30 pub name: Option<String>,
31 pub platform: Option<String>,
32 pub client: Option<String>,
33 pub client_version: Option<String>,
34 pub ip_address: Option<String>,
35 pub mac_address: Option<String>,
36 pub hostname: Option<String>,
37 pub sync_mode: SyncMode,
38 pub sync_enabled: bool,
39 pub sync_config: Option<Value>,
40 pub last_seen: Option<String>,
41 pub created_at: String,
42 pub updated_at: String,
43}
44
45#[derive(Debug, Clone)]
47pub struct RegisterDevice {
48 pub body: Value,
49}
50
51impl Endpoint for RegisterDevice {
52 type Output = DeviceCreateResponse;
53
54 fn method(&self) -> &'static str {
55 "POST"
56 }
57
58 fn path(&self) -> String {
59 "/api/devices".into()
60 }
61
62 fn body(&self) -> Option<Value> {
63 Some(self.body.clone())
64 }
65}
66
67#[derive(Debug, Clone, Default)]
69pub struct ListDevices;
70
71impl Endpoint for ListDevices {
72 type Output = Vec<DeviceSchema>;
73
74 fn method(&self) -> &'static str {
75 "GET"
76 }
77
78 fn path(&self) -> String {
79 "/api/devices".into()
80 }
81}
82
83#[derive(Debug, Clone)]
85pub struct GetDevice {
86 pub device_id: String,
87}
88
89impl Endpoint for GetDevice {
90 type Output = DeviceSchema;
91
92 fn method(&self) -> &'static str {
93 "GET"
94 }
95
96 fn path(&self) -> String {
97 format!("/api/devices/{}", self.device_id)
98 }
99}
100
101#[derive(Debug, Clone)]
103pub struct UpdateDevice {
104 pub device_id: String,
105 pub body: Value,
106}
107
108impl Endpoint for UpdateDevice {
109 type Output = DeviceSchema;
110
111 fn method(&self) -> &'static str {
112 "PUT"
113 }
114
115 fn path(&self) -> String {
116 format!("/api/devices/{}", self.device_id)
117 }
118
119 fn body(&self) -> Option<Value> {
120 Some(self.body.clone())
121 }
122}
123
124#[derive(Debug, Clone)]
126pub struct DeleteDevice {
127 pub device_id: String,
128}
129
130impl Endpoint for DeleteDevice {
131 type Output = Value;
132
133 fn method(&self) -> &'static str {
134 "DELETE"
135 }
136
137 fn path(&self) -> String {
138 format!("/api/devices/{}", self.device_id)
139 }
140}