Skip to main content

romm_api/endpoints/
client_tokens.rs

1//! API endpoints for managing client tokens.
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use super::Endpoint;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ClientTokenCreateSchema {
9    pub id: i64,
10    pub name: String,
11    pub scopes: Vec<String>,
12    pub expires_at: Option<String>,
13    pub last_used_at: Option<String>,
14    pub created_at: String,
15    pub user_id: i64,
16    pub raw_token: String,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ExchangeClientTokenRequest {
21    pub code: String,
22}
23
24#[derive(Debug, Clone)]
25pub struct ExchangeClientToken {
26    pub code: String,
27}
28
29impl Endpoint for ExchangeClientToken {
30    type Output = ClientTokenCreateSchema;
31
32    fn method(&self) -> &'static str {
33        "POST"
34    }
35
36    fn path(&self) -> String {
37        "/api/client-tokens/exchange".into()
38    }
39
40    fn body(&self) -> Option<Value> {
41        let req = ExchangeClientTokenRequest {
42            code: self.code.clone(),
43        };
44        serde_json::to_value(&req).ok()
45    }
46}