romm-cli 0.22.0

Rust-based CLI and TUI for the ROMM API
Documentation
//! Small service objects that wrap `RommClient` for higher-level operations.
//!
//! These are used by the CLI commands to keep a clear separation between
//! \"how we talk to ROMM\" (HTTP) and \"what we want to do\" (list
//! platforms, search ROMs, etc.).

use anyhow::Result;

use crate::client::RommClient;
use crate::endpoints::{
    platforms::{GetPlatform, ListPlatforms},
    roms::{GetRom, GetRoms},
};
use crate::types::{Platform, Rom, RomList};

/// Service encapsulating platform-related operations.
pub struct PlatformService<'a> {
    client: &'a RommClient,
}

impl<'a> PlatformService<'a> {
    pub fn new(client: &'a RommClient) -> Self {
        Self { client }
    }

    /// List all platforms from the ROMM API.
    pub async fn list_platforms(&self) -> Result<Vec<Platform>> {
        let platforms = self.client.call(&ListPlatforms).await?;
        Ok(platforms)
    }

    /// Get a single platform by ID.
    pub async fn get_platform(&self, id: u64) -> Result<Platform> {
        let platform = self.client.call(&GetPlatform { id }).await?;
        Ok(platform)
    }
}

/// Service encapsulating ROM-related operations.
pub struct RomService<'a> {
    client: &'a RommClient,
}

impl<'a> RomService<'a> {
    pub fn new(client: &'a RommClient) -> Self {
        Self { client }
    }

    /// Search/list ROMs using a fully-configured `GetRoms` descriptor.
    pub async fn search_roms(&self, ep: &GetRoms) -> Result<RomList> {
        let results = self.client.call(ep).await?;
        Ok(results)
    }

    /// Get a single ROM by ID.
    pub async fn get_rom(&self, id: u64) -> Result<Rom> {
        let rom = self.client.call(&GetRom { id }).await?;
        Ok(rom)
    }
}