freedom_api/extensions/
user.rs1use std::future::Future;
2
3use crate::{api::Api, error::Error};
4use freedom_models::{
5 account::Account,
6 user::{User, WhoAmI},
7};
8
9pub trait WhoAmIExt {
10 fn get_id(&self) -> Result<i32, Error>;
11
12 fn get_user<C>(&self, client: &C) -> impl Future<Output = Result<User, Error>> + Send + Sync
13 where
14 C: Api;
15}
16
17impl WhoAmIExt for WhoAmI {
18 fn get_id(&self) -> Result<i32, Error> {
19 Ok(self.id)
20 }
21
22 async fn get_user<C>(&self, client: &C) -> Result<User, Error>
23 where
24 C: Api,
25 {
26 super::get_item("users", &self.links, client).await
27 }
28}
29
30pub trait UserExt {
31 fn get_id(&self) -> Result<i32, Error>;
32
33 fn get_account<C>(
34 &self,
35 client: &C,
36 ) -> impl Future<Output = Result<Account, Error>> + Send + Sync
37 where
38 C: Api;
39}
40
41impl UserExt for User {
42 fn get_id(&self) -> Result<i32, Error> {
43 super::get_id("self", &self.links)
44 }
45
46 async fn get_account<C>(&self, client: &C) -> Result<Account, Error>
47 where
48 C: Api,
49 {
50 super::get_content("account", &self.links, client).await
51 }
52}