Skip to main content

romm_cli/
services.rs

1//! Small service objects that wrap `RommClient` for higher-level operations.
2//!
3//! These are used by the CLI commands to keep a clear separation between
4//! \"how we talk to ROMM\" (HTTP) and \"what we want to do\" (list
5//! platforms, search ROMs, etc.).
6
7use anyhow::Result;
8
9use crate::client::RommClient;
10use crate::endpoints::{platforms::ListPlatforms, roms::GetRoms};
11use crate::types::{Platform, RomList};
12
13/// Service encapsulating platform-related operations.
14pub struct PlatformService<'a> {
15    client: &'a RommClient,
16}
17
18impl<'a> PlatformService<'a> {
19    pub fn new(client: &'a RommClient) -> Self {
20        Self { client }
21    }
22
23    /// List all platforms from the ROMM API.
24    pub async fn list_platforms(&self) -> Result<Vec<Platform>> {
25        let platforms = self.client.call(&ListPlatforms).await?;
26        Ok(platforms)
27    }
28}
29
30/// Service encapsulating ROM-related operations.
31pub struct RomService<'a> {
32    client: &'a RommClient,
33}
34
35impl<'a> RomService<'a> {
36    pub fn new(client: &'a RommClient) -> Self {
37        Self { client }
38    }
39
40    /// Search/list ROMs using a fully-configured `GetRoms` descriptor.
41    pub async fn search_roms(&self, ep: &GetRoms) -> Result<RomList> {
42        let results = self.client.call(ep).await?;
43        Ok(results)
44    }
45}