Skip to main content

romm_api/endpoints/
platforms.rs

1//! Platform-related API endpoints.
2//!
3//! Use these endpoints to list, retrieve, update, or delete gaming platforms
4//! in the RomM database.
5
6use crate::types::Platform;
7
8use super::Endpoint;
9use serde_json::Value;
10
11/// List all platforms.
12#[derive(Debug, Default, Clone)]
13pub struct ListPlatforms;
14
15impl Endpoint for ListPlatforms {
16    type Output = Vec<Platform>;
17
18    fn method(&self) -> &'static str {
19        "GET"
20    }
21
22    fn path(&self) -> String {
23        "/api/platforms".into()
24    }
25}
26
27/// Retrieve a platform by ID.
28#[derive(Debug, Clone)]
29pub struct GetPlatform {
30    pub id: u64,
31}
32
33impl Endpoint for GetPlatform {
34    type Output = Platform;
35
36    fn method(&self) -> &'static str {
37        "GET"
38    }
39
40    fn path(&self) -> String {
41        format!("/api/platforms/{}", self.id)
42    }
43}
44
45/// `GET /api/platforms/supported` — IGDB-supported platform catalog.
46#[derive(Debug, Default, Clone)]
47pub struct ListSupportedPlatforms;
48
49impl Endpoint for ListSupportedPlatforms {
50    type Output = Value;
51
52    fn method(&self) -> &'static str {
53        "GET"
54    }
55
56    fn path(&self) -> String {
57        "/api/platforms/supported".into()
58    }
59}
60
61/// `PUT /api/platforms/{id}` — update platform metadata (JSON body).
62#[derive(Debug, Clone)]
63pub struct PutPlatform {
64    pub id: u64,
65    pub body: Value,
66}
67
68impl Endpoint for PutPlatform {
69    type Output = Value;
70
71    fn method(&self) -> &'static str {
72        "PUT"
73    }
74
75    fn path(&self) -> String {
76        format!("/api/platforms/{}", self.id)
77    }
78
79    fn body(&self) -> Option<Value> {
80        Some(self.body.clone())
81    }
82}
83
84/// `DELETE /api/platforms/{id}`
85#[derive(Debug, Clone)]
86pub struct DeletePlatform {
87    pub id: u64,
88}
89
90impl Endpoint for DeletePlatform {
91    type Output = Value;
92
93    fn method(&self) -> &'static str {
94        "DELETE"
95    }
96
97    fn path(&self) -> String {
98        format!("/api/platforms/{}", self.id)
99    }
100}