Skip to content

Commit 2686c02

Browse files
committed
chore: formatting
1 parent 041901a commit 2686c02

File tree

46 files changed

+692
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+692
-435
lines changed

crates/client-macros/src/lib.rs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct APIEndpoint {
1212
response: Type,
1313
request: Type,
1414
// TODO: don't use Expr here
15-
extra_args: HashMap<String, Option<Expr>>
15+
extra_args: HashMap<String, Option<Expr>>,
1616
}
1717

1818
impl Parse for APIEndpoint {
@@ -40,7 +40,7 @@ impl Parse for APIEndpoint {
4040
url,
4141
request,
4242
response,
43-
extra_args
43+
extra_args,
4444
})
4545
}
4646
}
@@ -68,7 +68,7 @@ pub fn api(input: TokenStream) -> TokenStream {
6868
url,
6969
response,
7070
request,
71-
extra_args
71+
extra_args,
7272
} = syn::parse_macro_input!(input as APIEndpoint);
7373

7474
if method != "get"
@@ -81,8 +81,8 @@ pub fn api(input: TokenStream) -> TokenStream {
8181
method.span(),
8282
"Invalid HTTP method. Must be one of: get, post, put, patch, delete",
8383
)
84-
.to_compile_error()
85-
.into();
84+
.to_compile_error()
85+
.into();
8686
}
8787

8888
let has_request = !matches!(request, Type::Never(_));
@@ -95,8 +95,8 @@ pub fn api(input: TokenStream) -> TokenStream {
9595
response.span(),
9696
"Response type must be a wrapped Result type",
9797
)
98-
.to_compile_error()
99-
.into();
98+
.to_compile_error()
99+
.into();
100100
}
101101
let ident = segments[0].ident.clone();
102102
// TODO: hack lol
@@ -135,37 +135,36 @@ pub fn api(input: TokenStream) -> TokenStream {
135135
}
136136
};
137137

138-
let send_request =
139-
if let Some(request_expr) = extra_args.get("request") {
138+
let send_request = if let Some(request_expr) = extra_args.get("request") {
139+
quote! {
140+
#request_expr
141+
}
142+
} else if has_request {
143+
if method == "get" {
140144
quote! {
141-
#request_expr
142-
}
143-
} else if has_request {
144-
if method == "get" {
145-
quote! {
146-
client
147-
.#method(format!("{pronto_base_url}{}", #url))
148-
.query(&request)
149-
.send()
150-
.await?
151-
}
152-
} else {
153-
quote! {
154-
client
155-
.#method(format!("{pronto_base_url}{}", #url))
156-
.json(&request)
157-
.send()
158-
.await?
159-
}
145+
client
146+
.#method(format!("{pronto_base_url}{}", #url))
147+
.query(&request)
148+
.send()
149+
.await?
160150
}
161151
} else {
162152
quote! {
163153
client
164154
.#method(format!("{pronto_base_url}{}", #url))
155+
.json(&request)
165156
.send()
166157
.await?
167158
}
168-
};
159+
}
160+
} else {
161+
quote! {
162+
client
163+
.#method(format!("{pronto_base_url}{}", #url))
164+
.send()
165+
.await?
166+
}
167+
};
169168

170169
let function_name = quote! {
171170
#method
@@ -186,18 +185,18 @@ pub fn api(input: TokenStream) -> TokenStream {
186185

187186
// Build the output
188187
let expanded = quote! {
189-
#[doc = "Sends a #method request to #url."]
190-
pub async fn #function_name(
191-
#types
192-
) -> Result<#response, crate::ResponseError> {
193-
let initial_time = std::time::Instant::now();
194-
let r = #send_request;
195-
let elapsed = initial_time.elapsed();
196-
log::debug!(target: "request_perf", "Network: {} ms", elapsed.as_millis());
197-
#process
198-
#parse
199-
}
200-
};
188+
#[doc = "Sends a #method request to #url."]
189+
pub async fn #function_name(
190+
#types
191+
) -> Result<#response, crate::ResponseError> {
192+
let initial_time = std::time::Instant::now();
193+
let r = #send_request;
194+
let elapsed = initial_time.elapsed();
195+
log::debug!(target: "request_perf", "Network: {} ms", elapsed.as_millis());
196+
#process
197+
#parse
198+
}
199+
};
201200

202201
TokenStream::from(expanded)
203202
}

crates/client/src/client/bubble.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ use crate::bubble_history::GetBubbleHistoryResponse;
22
use crate::bubble_info::GetBubbleInfoResponse;
33
use crate::bubble_list::GetBubbleListResponse;
44
use crate::bubble_mark::PostBubbleMarkRequest;
5-
use crate::{bubble_create, bubble_delete, bubble_history, bubble_info, bubble_list, bubble_mark, bubble_membership_search, bubble_update, dm_create, membership_update, MembershipUpdateModification, NotificationsPreference, PostBubbleMembershipSearchRequest, PostMembershipUpdateRequest, ProntoClient, ResponseError};
5+
use crate::{
6+
bubble_create, bubble_delete, bubble_history, bubble_info, bubble_list, bubble_mark,
7+
bubble_membership_search, bubble_update, dm_create, membership_update,
8+
MembershipUpdateModification, NotificationsPreference, PostBubbleMembershipSearchRequest,
9+
PostMembershipUpdateRequest, ProntoClient, ResponseError,
10+
};
611

712
impl ProntoClient {
813
pub async fn create_dm(
@@ -229,20 +234,30 @@ impl ProntoClient {
229234
.to_result()?)
230235
}
231236

232-
pub async fn pin_message(&self, bubble_id: u64, message_id: u64, end: chrono::NaiveDateTime) -> Result<bubble_update::BubbleUpdateResponse, ResponseError> {
237+
pub async fn pin_message(
238+
&self,
239+
bubble_id: u64,
240+
message_id: u64,
241+
end: chrono::NaiveDateTime,
242+
) -> Result<bubble_update::BubbleUpdateResponse, ResponseError> {
233243
Ok(bubble_update::post(
234244
&self.api_base_url,
235245
&self.http_client,
236246
bubble_update::PostBubbleUpdateRequest {
237247
bubble_id,
238-
modification: bubble_update::BubbleUpdateModification::SetPinnedMessage((message_id, end)),
248+
modification: bubble_update::BubbleUpdateModification::SetPinnedMessage((
249+
message_id, end,
250+
)),
239251
},
240252
)
241-
.await?
242-
.to_result()?)
253+
.await?
254+
.to_result()?)
243255
}
244256

245-
pub async fn unpin_message(&self, bubble_id: u64) -> Result<bubble_update::BubbleUpdateResponse, ResponseError> {
257+
pub async fn unpin_message(
258+
&self,
259+
bubble_id: u64,
260+
) -> Result<bubble_update::BubbleUpdateResponse, ResponseError> {
246261
Ok(bubble_update::post(
247262
&self.api_base_url,
248263
&self.http_client,
@@ -251,8 +266,8 @@ impl ProntoClient {
251266
modification: bubble_update::BubbleUpdateModification::RemovePinnedMessage(),
252267
},
253268
)
254-
.await?
255-
.to_result()?)
269+
.await?
270+
.to_result()?)
256271
}
257272

258273
pub async fn set_bubble_title(
@@ -268,8 +283,8 @@ impl ProntoClient {
268283
modification: bubble_update::BubbleUpdateModification::SetTitle(title),
269284
},
270285
)
271-
.await?
272-
.to_result()?)
286+
.await?
287+
.to_result()?)
273288
}
274289

275290
pub async fn set_bubble_category(
@@ -285,32 +300,37 @@ impl ProntoClient {
285300
modification: bubble_update::BubbleUpdateModification::SetCategory(category_id),
286301
},
287302
)
288-
.await?
289-
.to_result()?)
303+
.await?
304+
.to_result()?)
290305
}
291306

292307
pub async fn modify_bubble_permission(
293308
&self,
294309
bubble_id: u64,
295310
name: String,
296-
value: String
311+
value: String,
297312
) -> Result<bubble_update::BubbleUpdateResponse, ResponseError> {
298313
Ok(bubble_update::post(
299314
&self.api_base_url,
300315
&self.http_client,
301316
bubble_update::PostBubbleUpdateRequest {
302317
bubble_id,
303-
modification: bubble_update::BubbleUpdateModification::ModifyPermission(crate::Property {
304-
key: name,
305-
value: serde_json::Value::String(value)
306-
}),
318+
modification: bubble_update::BubbleUpdateModification::ModifyPermission(
319+
crate::Property {
320+
key: name,
321+
value: serde_json::Value::String(value),
322+
},
323+
),
307324
},
308325
)
309-
.await?
310-
.to_result()?)
326+
.await?
327+
.to_result()?)
311328
}
312329

313-
pub async fn delete_bubble(&self, bubble_id: u64) -> Result<bubble_delete::PostBubbleDeleteResponse, ResponseError> {
330+
pub async fn delete_bubble(
331+
&self,
332+
bubble_id: u64,
333+
) -> Result<bubble_delete::PostBubbleDeleteResponse, ResponseError> {
314334
Ok(bubble_delete::post(
315335
&self.api_base_url,
316336
&self.http_client,

crates/client/src/client/user.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ impl ProntoClient {
2323
&self,
2424
request: user_search::GetUserSearchRequest,
2525
) -> Result<user_search::GetUserSearchResponse, ResponseError> {
26-
Ok(user_search::get(
27-
&self.api_base_url,
28-
&self.http_client,
29-
request,
26+
Ok(
27+
user_search::get(&self.api_base_url, &self.http_client, request)
28+
.await?
29+
.to_result()?,
3030
)
31-
.await?
32-
.to_result()?)
3331
}
3432
}

crates/client/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub use routes::*;
1818

1919
pub mod api_error;
2020
mod client;
21+
pub(crate) mod custom_json;
2122
pub mod models;
2223
pub mod routes;
2324
pub(crate) mod serde_datetime;
24-
pub(crate) mod custom_json;
2525

2626
#[derive(Debug, Deserialize, Serialize)]
2727
#[serde(untagged)]
@@ -232,15 +232,24 @@ mod tests {
232232
#[tokio::test]
233233
async fn test_get_announcement_list() {
234234
let client = get_client().await;
235-
client.announcement_list("RECEIVED".to_string()).await.unwrap();
235+
client
236+
.announcement_list("RECEIVED".to_string())
237+
.await
238+
.unwrap();
236239
}
237240

238241
#[tokio::test]
239242
async fn test_get_task_list() {
240243
let client = get_client().await;
241244
let response = client.current_user_info().await.unwrap();
242-
client.task_list(response.user.organizations[0].id, false).await.unwrap();
243-
client.task_list(response.user.organizations[0].id, true).await.unwrap();
245+
client
246+
.task_list(response.user.organizations[0].id, false)
247+
.await
248+
.unwrap();
249+
client
250+
.task_list(response.user.organizations[0].id, true)
251+
.await
252+
.unwrap();
244253
}
245254

246255
#[tokio::test]

crates/client/src/models/announcement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{UserInfo};
1+
use crate::UserInfo;
22
use serde::{Deserialize, Serialize};
33

44
#[derive(Clone, Debug, Serialize, Deserialize)]

crates/client/src/models/bubble.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{Category, Message};
21
use crate::UserInfo;
2+
use crate::{Category, Message};
33
use crate::{Membership, MembershipInfo};
44
use serde::{Deserialize, Serialize};
55

@@ -61,5 +61,5 @@ pub struct Bubble {
6161
pub category: Option<Category>,
6262
pub memberships: Option<Vec<BubbleMembershipItem>>,
6363
pub pinned_message: Option<Message>,
64-
pub pinned_message_user: Option<UserInfo>
64+
pub pinned_message_user: Option<UserInfo>,
6565
}

crates/client/src/models/property.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ use serde_json::Value;
44
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
55
pub struct Property {
66
pub key: String,
7-
pub value: Value
7+
pub value: Value,
88
}

crates/client/src/routes/bubble_history.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ pub async fn get(
3232
.query(&json!({ "bubble_id": bubble_id }))
3333
.send()
3434
}
35-
.await?;
35+
.await?;
3636
let elapsed = initial_time.elapsed();
3737
log::debug!(target : "request_perf" , "Network: {} ms" , elapsed . as_millis ());
3838
let text = r.text().await?;
39-
log::trace!("Response: {}" , text);
39+
log::trace!("Response: {}", text);
4040
let json = serde_json::from_str(&text);
4141
match json {
42-
Ok(json) => { Ok(json) }
42+
Ok(json) => Ok(json),
4343
Err(_e) => {
4444
let json = serde_json::from_str::<GetBubbleHistoryResponse>(&text);
4545
let e = json.unwrap_err();
46-
log::error!("Error parsing json response: {:?}." , e );
46+
log::error!("Error parsing json response: {:?}.", e);
4747
let json = serde_json::from_str::<serde_json::Value>(&text);
48-
if json.is_err() { return Err(crate::ResponseError::NotJson(text)); }
48+
if json.is_err() {
49+
return Err(crate::ResponseError::NotJson(text));
50+
}
4951
Err(crate::ResponseError::from(e))
5052
}
5153
}

0 commit comments

Comments
 (0)