Skip to main content

esi_openapi/groups/
fittings.rs

1#![allow(unused)]
2
3use crate::prelude::*;
4
5/// Endpoints for Fittings
6pub struct FittingsGroup<'a> {
7    pub(crate) esi: &'a Esi,
8}
9
10#[allow(missing_docs)]
11#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
12/// The slot or bay an item occupies in a fitting. Variant names match the
13/// spec values exactly.
14pub enum FittingFlag {
15    Cargo,
16    DroneBay,
17    FighterBay,
18    HiSlot0,
19    HiSlot1,
20    HiSlot2,
21    HiSlot3,
22    HiSlot4,
23    HiSlot5,
24    HiSlot6,
25    HiSlot7,
26    Invalid,
27    LoSlot0,
28    LoSlot1,
29    LoSlot2,
30    LoSlot3,
31    LoSlot4,
32    LoSlot5,
33    LoSlot6,
34    LoSlot7,
35    MedSlot0,
36    MedSlot1,
37    MedSlot2,
38    MedSlot3,
39    MedSlot4,
40    MedSlot5,
41    MedSlot6,
42    MedSlot7,
43    RigSlot0,
44    RigSlot1,
45    RigSlot2,
46    ServiceSlot0,
47    ServiceSlot1,
48    ServiceSlot2,
49    ServiceSlot3,
50    ServiceSlot4,
51    ServiceSlot5,
52    ServiceSlot6,
53    ServiceSlot7,
54    SubSystemSlot0,
55    SubSystemSlot1,
56    SubSystemSlot2,
57    SubSystemSlot3,
58    /// A value not known to this version of the crate.
59    #[serde(other)]
60    Unrecognized,
61}
62
63#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
64/// An item in a fitting.
65pub struct FittingItem {
66    /// Slot or bay of the item.
67    pub flag: FittingFlag,
68    /// Quantity of the item.
69    pub quantity: i64,
70    /// Type ID of the item.
71    pub type_id: i64,
72}
73
74#[derive(Debug, Deserialize, Serialize, Clone)]
75/// A saved ship fitting.
76pub struct Fitting {
77    /// Description of the fitting.
78    pub description: String,
79    /// ID of the fitting.
80    pub fitting_id: i64,
81    /// Items of the fitting.
82    pub items: Vec<FittingItem>,
83    /// Name of the fitting.
84    pub name: String,
85    /// Type ID of the ship.
86    pub ship_type_id: i64,
87}
88
89#[derive(Debug, Serialize, Clone)]
90/// The body of a request to save a new fitting.
91pub struct NewFitting {
92    /// Description of the fitting.
93    pub description: String,
94    /// Items of the fitting.
95    pub items: Vec<FittingItem>,
96    /// Name of the fitting.
97    pub name: String,
98    /// Type ID of the ship.
99    pub ship_type_id: i64,
100}
101
102impl FittingsGroup<'_> {
103    api_get!(
104        /// Return the fittings saved by a character.
105        get_character_fittings,
106        "GetCharactersCharacterIdFittings",
107        RequestType::Authenticated,
108        Vec<Fitting>,
109        (character_id: i64) => "{character_id}"
110    );
111
112    api_post!(
113        /// Save a new fitting. Returns the ID of the created fitting.
114        create_character_fitting,
115        "PostCharactersCharacterIdFittings",
116        RequestType::Authenticated,
117        i64,
118        (character_id: i64) => "{character_id}",
119        fitting: &NewFitting,
120    );
121
122    api_delete!(
123        /// Delete a saved fitting.
124        delete_character_fitting,
125        "DeleteCharactersCharacterIdFittingsFittingId",
126        RequestType::Authenticated,
127        (),
128        (character_id: i64) => "{character_id}",
129        (fitting_id: i64) => "{fitting_id}"
130    );
131}
132
133#[cfg(test)]
134mod fittings_tests {
135    use super::*;
136
137    #[test]
138    fn test_parse_fitting() {
139        let json = r#"[{"description": "d", "fitting_id": 3000000000, "name": "n", "ship_type_id": 587,
140            "items": [{"flag": "HiSlot0", "quantity": 1, "type_id": 3001},
141                      {"flag": "NewSlot", "quantity": 2, "type_id": 1}]}]"#;
142        let fits: Vec<Fitting> = serde_json::from_str(json).unwrap();
143        assert_eq!(fits[0].fitting_id, 3_000_000_000);
144        assert_eq!(fits[0].items[0].flag, FittingFlag::HiSlot0);
145        assert_eq!(fits[0].items[1].flag, FittingFlag::Unrecognized);
146    }
147
148    #[test]
149    fn test_serialize_new_fitting() {
150        let f = NewFitting {
151            description: "d".into(),
152            items: vec![FittingItem {
153                flag: FittingFlag::SubSystemSlot3,
154                quantity: 1,
155                type_id: 5,
156            }],
157            name: "n".into(),
158            ship_type_id: 1,
159        };
160        let v = serde_json::to_value(&f).unwrap();
161        assert_eq!(v["items"][0]["flag"], "SubSystemSlot3");
162    }
163}