artifacts/apis/
maps_api.rs1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct GetAllMapsParams {
9 pub content_type: Option<models::MapContentType>,
11 pub content_code: Option<String>,
13 pub page: Option<u32>,
15 pub size: Option<u32>,
17}
18
19impl GetAllMapsParams {
20 pub fn new(
21 content_type: Option<models::MapContentType>,
22 content_code: Option<String>,
23 page: Option<u32>,
24 size: Option<u32>,
25 ) -> Self {
26 Self {
27 content_type,
28 content_code,
29 page,
30 size,
31 }
32 }
33}
34
35#[derive(Clone, Debug)]
37pub struct GetMapParams {
38 pub x: i32,
40 pub y: i32,
42}
43
44impl GetMapParams {
45 pub fn new(x: i32, y: i32) -> Self {
46 Self { x, y }
47 }
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetAllMapsError {}
54
55impl TryFrom<StatusCode> for GetAllMapsError {
56 type Error = &'static str;
57 #[allow(clippy::match_single_binding)]
58 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
59 match status.as_u16() {
60 _ => Err("status code not in spec"),
61 }
62 }
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetMapError {
69 Status404,
71}
72
73impl TryFrom<StatusCode> for GetMapError {
74 type Error = &'static str;
75 #[allow(clippy::match_single_binding)]
76 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
77 match status.as_u16() {
78 404 => Ok(Self::Status404),
79 _ => Err("status code not in spec"),
80 }
81 }
82}
83
84pub async fn get_all_maps(
86 configuration: &configuration::Configuration,
87 params: GetAllMapsParams,
88) -> Result<models::DataPageMapSchema, Error<GetAllMapsError>> {
89 let local_var_configuration = configuration;
90
91 let content_type = params.content_type;
93 let content_code = params.content_code;
95 let page = params.page;
97 let size = params.size;
99
100 let local_var_client = &local_var_configuration.client;
101
102 let local_var_uri_str = format!("{}/maps", local_var_configuration.base_path);
103 let mut local_var_req_builder =
104 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
105
106 if let Some(ref local_var_str) = content_type {
107 local_var_req_builder =
108 local_var_req_builder.query(&[("content_type", &local_var_str.to_string())]);
109 }
110 if let Some(ref local_var_str) = content_code {
111 local_var_req_builder =
112 local_var_req_builder.query(&[("content_code", &local_var_str.to_string())]);
113 }
114 if let Some(ref local_var_str) = page {
115 local_var_req_builder =
116 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
117 }
118 if let Some(ref local_var_str) = size {
119 local_var_req_builder =
120 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
121 }
122 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
123 local_var_req_builder =
124 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
125 }
126
127 let local_var_req = local_var_req_builder.build()?;
128 let local_var_resp = local_var_client.execute(local_var_req).await?;
129
130 let local_var_status = local_var_resp.status();
131 let local_var_content = local_var_resp.text().await?;
132
133 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
134 serde_json::from_str(&local_var_content).map_err(Error::from)
135 } else {
136 let local_var_entity: Option<GetAllMapsError> = local_var_status.try_into().ok();
137 let local_var_error = ResponseContent {
138 status: local_var_status,
139 content: local_var_content,
140 entity: local_var_entity,
141 };
142 Err(Error::ResponseError(local_var_error))
143 }
144}
145
146pub async fn get_map(
148 configuration: &configuration::Configuration,
149 params: GetMapParams,
150) -> Result<models::MapResponseSchema, Error<GetMapError>> {
151 let local_var_configuration = configuration;
152
153 let x = params.x;
155 let y = params.y;
157
158 let local_var_client = &local_var_configuration.client;
159
160 let local_var_uri_str = format!(
161 "{}/maps/{x}/{y}",
162 local_var_configuration.base_path,
163 x = x,
164 y = y
165 );
166 let mut local_var_req_builder =
167 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
168
169 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170 local_var_req_builder =
171 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
172 }
173
174 let local_var_req = local_var_req_builder.build()?;
175 let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177 let local_var_status = local_var_resp.status();
178 let local_var_content = local_var_resp.text().await?;
179
180 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181 serde_json::from_str(&local_var_content).map_err(Error::from)
182 } else {
183 let local_var_entity: Option<GetMapError> = local_var_status.try_into().ok();
184 let local_var_error = ResponseContent {
185 status: local_var_status,
186 content: local_var_content,
187 entity: local_var_entity,
188 };
189 Err(Error::ResponseError(local_var_error))
190 }
191}