robespierre_http/
relationships.rs1use robespierre_models::{
2 id::UserId,
3 users::{Relationship, RelationshipStatus},
4};
5
6use super::impl_prelude::*;
7
8impl Http {
9 pub async fn fetch_relationships(&self) -> Result<Vec<Relationship>> {
11 Ok(self
12 .client_user_session_auth_type()
13 .get(ep!(self, "/users/relationships"))
14 .send()
15 .await?
16 .error_for_status()?
17 .json()
18 .await?)
19 }
20
21 pub async fn fetch_relationship(&self, user_id: UserId) -> Result<SingleRelationshipResponse> {
23 Ok(self
24 .client_user_session_auth_type()
25 .get(ep!(self, "/users/{}/relationship" user_id))
26 .send()
27 .await?
28 .error_for_status()?
29 .json()
30 .await?)
31 }
32
33 pub async fn send_friend_request(&self, username: &str) -> Result<SingleRelationshipResponse> {
35 Ok(self
36 .client_user_session_auth_type()
37 .put(ep!(self, "/users/{}/friend" username))
38 .send()
39 .await?
40 .error_for_status()?
41 .json::<SingleRelationshipResponse>()
42 .await?)
43 }
44
45 pub async fn deny_friend_request(&self, username: &str) -> Result<SingleRelationshipResponse> {
47 Ok(self
48 .client_user_session_auth_type()
49 .delete(ep!(self, "/users/{}/friend" username))
50 .send()
51 .await?
52 .error_for_status()?
53 .json::<SingleRelationshipResponse>()
54 .await?)
55 }
56
57 pub async fn remove_friend(&self, username: &str) -> Result<SingleRelationshipResponse> {
58 self.deny_friend_request(username).await
59 }
60
61 pub async fn block_user(&self, user_id: UserId) -> Result<SingleRelationshipResponse> {
63 Ok(self
64 .client_user_session_auth_type()
65 .put(ep!(self, "/users/{}/block" user_id))
66 .send()
67 .await?
68 .error_for_status()?
69 .json::<SingleRelationshipResponse>()
70 .await?)
71 }
72
73 pub async fn unblock(&self, user_id: UserId) -> Result<SingleRelationshipResponse> {
75 Ok(self
76 .client_user_session_auth_type()
77 .delete(ep!(self, "/users/{}/block" user_id))
78 .send()
79 .await?
80 .error_for_status()?
81 .json::<SingleRelationshipResponse>()
82 .await?)
83 }
84}
85
86#[derive(serde::Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
87pub struct SingleRelationshipResponse {
88 pub status: RelationshipStatus,
89}