use anyhow::Result;
use crate::client::RommClient;
use crate::endpoints::{
platforms::{GetPlatform, ListPlatforms},
roms::{GetRom, GetRoms},
};
use crate::types::{Platform, Rom, RomList};
pub struct PlatformService<'a> {
client: &'a RommClient,
}
impl<'a> PlatformService<'a> {
pub fn new(client: &'a RommClient) -> Self {
Self { client }
}
pub async fn list_platforms(&self) -> Result<Vec<Platform>> {
let platforms = self.client.call(&ListPlatforms).await?;
Ok(platforms)
}
pub async fn get_platform(&self, id: u64) -> Result<Platform> {
let platform = self.client.call(&GetPlatform { id }).await?;
Ok(platform)
}
}
pub struct RomService<'a> {
client: &'a RommClient,
}
impl<'a> RomService<'a> {
pub fn new(client: &'a RommClient) -> Self {
Self { client }
}
pub async fn search_roms(&self, ep: &GetRoms) -> Result<RomList> {
let results = self.client.call(ep).await?;
Ok(results)
}
pub async fn get_rom(&self, id: u64) -> Result<Rom> {
let rom = self.client.call(&GetRom { id }).await?;
Ok(rom)
}
}