artifacts/apis/
items_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6/// struct for passing parameters to the method [`get_all_items`]
7#[derive(Clone, Debug)]
8pub struct GetAllItemsParams {
9    /// Name of the item.
10    pub name: Option<String>,
11    /// Minimum level items.
12    pub min_level: Option<u32>,
13    /// Maximum level items.
14    pub max_level: Option<u32>,
15    /// Type of items.
16    pub r#type: Option<models::ItemType>,
17    /// Skill to craft items.
18    pub craft_skill: Option<models::CraftSkill>,
19    /// Item code of items used as material for crafting.
20    pub craft_material: Option<String>,
21    /// Page number
22    pub page: Option<u32>,
23    /// Page size
24    pub size: Option<u32>,
25}
26
27impl GetAllItemsParams {
28    pub fn new(
29        name: Option<String>,
30        min_level: Option<u32>,
31        max_level: Option<u32>,
32        r#type: Option<models::ItemType>,
33        craft_skill: Option<models::CraftSkill>,
34        craft_material: Option<String>,
35        page: Option<u32>,
36        size: Option<u32>,
37    ) -> Self {
38        Self {
39            name,
40            min_level,
41            max_level,
42            r#type,
43            craft_skill,
44            craft_material,
45            page,
46            size,
47        }
48    }
49}
50
51/// struct for passing parameters to the method [`get_item`]
52#[derive(Clone, Debug)]
53pub struct GetItemParams {
54    /// The code of the item.
55    pub code: String,
56}
57
58impl GetItemParams {
59    pub fn new(code: String) -> Self {
60        Self { code }
61    }
62}
63
64/// struct for typed errors of method [`get_all_items`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum GetAllItemsError {}
68
69impl TryFrom<StatusCode> for GetAllItemsError {
70    type Error = &'static str;
71    #[allow(clippy::match_single_binding)]
72    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
73        match status.as_u16() {
74            _ => Err("status code not in spec"),
75        }
76    }
77}
78
79/// struct for typed errors of method [`get_item`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetItemError {
83    /// Item not found.
84    Status404,
85}
86
87impl TryFrom<StatusCode> for GetItemError {
88    type Error = &'static str;
89    #[allow(clippy::match_single_binding)]
90    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
91        match status.as_u16() {
92            404 => Ok(Self::Status404),
93            _ => Err("status code not in spec"),
94        }
95    }
96}
97
98/// Fetch items details.
99pub async fn get_all_items(
100    configuration: &configuration::Configuration,
101    params: GetAllItemsParams,
102) -> Result<models::DataPageItemSchema, Error<GetAllItemsError>> {
103    let local_var_configuration = configuration;
104
105    // unbox the parameters
106    let name = params.name;
107    // unbox the parameters
108    let min_level = params.min_level;
109    // unbox the parameters
110    let max_level = params.max_level;
111    // unbox the parameters
112    let r#type = params.r#type;
113    // unbox the parameters
114    let craft_skill = params.craft_skill;
115    // unbox the parameters
116    let craft_material = params.craft_material;
117    // unbox the parameters
118    let page = params.page;
119    // unbox the parameters
120    let size = params.size;
121
122    let local_var_client = &local_var_configuration.client;
123
124    let local_var_uri_str = format!("{}/items", local_var_configuration.base_path);
125    let mut local_var_req_builder =
126        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
127
128    if let Some(ref local_var_str) = name {
129        local_var_req_builder =
130            local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
131    }
132    if let Some(ref local_var_str) = min_level {
133        local_var_req_builder =
134            local_var_req_builder.query(&[("min_level", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = max_level {
137        local_var_req_builder =
138            local_var_req_builder.query(&[("max_level", &local_var_str.to_string())]);
139    }
140    if let Some(ref local_var_str) = r#type {
141        local_var_req_builder =
142            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
143    }
144    if let Some(ref local_var_str) = craft_skill {
145        local_var_req_builder =
146            local_var_req_builder.query(&[("craft_skill", &local_var_str.to_string())]);
147    }
148    if let Some(ref local_var_str) = craft_material {
149        local_var_req_builder =
150            local_var_req_builder.query(&[("craft_material", &local_var_str.to_string())]);
151    }
152    if let Some(ref local_var_str) = page {
153        local_var_req_builder =
154            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
155    }
156    if let Some(ref local_var_str) = size {
157        local_var_req_builder =
158            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
161        local_var_req_builder =
162            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163    }
164
165    let local_var_req = local_var_req_builder.build()?;
166    let local_var_resp = local_var_client.execute(local_var_req).await?;
167
168    let local_var_status = local_var_resp.status();
169    let local_var_content = local_var_resp.text().await?;
170
171    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
172        serde_json::from_str(&local_var_content).map_err(Error::from)
173    } else {
174        let local_var_entity: Option<GetAllItemsError> = local_var_status.try_into().ok();
175        let local_var_error = ResponseContent {
176            status: local_var_status,
177            content: local_var_content,
178            entity: local_var_entity,
179        };
180        Err(Error::ResponseError(local_var_error))
181    }
182}
183
184/// Retrieve the details of a item.
185pub async fn get_item(
186    configuration: &configuration::Configuration,
187    params: GetItemParams,
188) -> Result<models::ItemResponseSchema, Error<GetItemError>> {
189    let local_var_configuration = configuration;
190
191    // unbox the parameters
192    let code = params.code;
193
194    let local_var_client = &local_var_configuration.client;
195
196    let local_var_uri_str = format!(
197        "{}/items/{code}",
198        local_var_configuration.base_path,
199        code = crate::apis::urlencode(code)
200    );
201    let mut local_var_req_builder =
202        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
203
204    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205        local_var_req_builder =
206            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
207    }
208
209    let local_var_req = local_var_req_builder.build()?;
210    let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212    let local_var_status = local_var_resp.status();
213    let local_var_content = local_var_resp.text().await?;
214
215    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
216        serde_json::from_str(&local_var_content).map_err(Error::from)
217    } else {
218        let local_var_entity: Option<GetItemError> = local_var_status.try_into().ok();
219        let local_var_error = ResponseContent {
220            status: local_var_status,
221            content: local_var_content,
222            entity: local_var_entity,
223        };
224        Err(Error::ResponseError(local_var_error))
225    }
226}