Skip to main content

romm_cli/endpoints/
roms.rs

1use crate::types::RomList;
2
3use super::Endpoint;
4
5/// Retrieve ROMs with optional filters.
6#[derive(Debug, Default, Clone)]
7pub struct GetRoms {
8    pub search_term: Option<String>,
9    pub platform_id: Option<u64>,
10    pub collection_id: Option<u64>,
11    pub limit: Option<u32>,
12    pub offset: Option<u32>,
13}
14
15impl Endpoint for GetRoms {
16    type Output = RomList;
17
18    fn method(&self) -> &'static str {
19        "GET"
20    }
21
22    fn path(&self) -> String {
23        "/api/roms".into()
24    }
25
26    fn query(&self) -> Vec<(String, String)> {
27        let mut q = Vec::new();
28
29        if let Some(term) = &self.search_term {
30            q.push(("search_term".into(), term.clone()));
31        }
32
33        // RomM API expects "platform_ids" (plural); repeat param for multiple values.
34        if let Some(pid) = self.platform_id {
35            q.push(("platform_ids".into(), pid.to_string()));
36        }
37
38        if let Some(cid) = self.collection_id {
39            q.push(("collection_id".into(), cid.to_string()));
40        }
41
42        if let Some(limit) = self.limit {
43            q.push(("limit".into(), limit.to_string()));
44        }
45
46        if let Some(offset) = self.offset {
47            q.push(("offset".into(), offset.to_string()));
48        }
49
50        q
51    }
52}
53
54/// Retrieve a single ROM by ID.
55#[derive(Debug, Clone)]
56pub struct GetRom {
57    pub id: u64,
58}
59
60impl Endpoint for GetRom {
61    type Output = crate::types::Rom;
62
63    fn method(&self) -> &'static str {
64        "GET"
65    }
66
67    fn path(&self) -> String {
68        format!("/api/roms/{}", self.id)
69    }
70}