freedom_api/extensions/
request.rs1use std::future::Future;
2
3use crate::{api::Api, error::Error};
4use freedom_models::{
5 band::Band,
6 satellite::Satellite,
7 site::{Site, SiteConfiguration},
8 task::{Task, TaskRequest},
9 user::User,
10};
11
12pub trait TaskRequestExt {
13 fn get_id(&self) -> Result<i32, Error>;
14
15 fn get_task<C>(
16 &self,
17 client: &C,
18 ) -> impl Future<Output = Result<<C as Api>::Container<Task>, Error>> + Send
19 where
20 C: Api + Send;
21
22 fn get_site<C>(&self, client: &C) -> impl Future<Output = Result<Site, Error>> + Send
23 where
24 C: Api + Send;
25
26 fn get_target_bands<C>(
27 &self,
28 client: &C,
29 ) -> impl Future<Output = Result<<C as Api>::Container<Vec<Band>>, Error>> + Send
30 where
31 C: Api + Send;
32
33 fn get_config<C>(
34 &self,
35 client: &C,
36 ) -> impl Future<Output = Result<SiteConfiguration, Error>> + Send
37 where
38 C: Api + Send;
39
40 fn get_satellite<C>(&self, client: &C) -> impl Future<Output = Result<Satellite, Error>> + Send
41 where
42 C: Api + Send;
43
44 fn get_user<C>(&self, client: &C) -> impl Future<Output = Result<User, Error>> + Send
45 where
46 C: Api + Send;
47}
48
49impl TaskRequestExt for TaskRequest {
50 fn get_id(&self) -> Result<i32, Error> {
51 super::get_id("self", &self.links)
52 }
53
54 async fn get_task<C>(&self, client: &C) -> Result<<C as Api>::Container<Task>, Error>
55 where
56 C: Api + Send,
57 {
58 super::get_item("task", &self.links, client).await
59 }
60
61 async fn get_site<C>(&self, client: &C) -> Result<Site, Error>
62 where
63 C: Api + Send,
64 {
65 super::get_content("site", &self.links, client).await
66 }
67
68 async fn get_target_bands<C>(
69 &self,
70 client: &C,
71 ) -> Result<<C as Api>::Container<Vec<Band>>, Error>
72 where
73 C: Api + Send,
74 {
75 super::get_embedded("targetBands", &self.links, client).await
76 }
77
78 async fn get_config<C>(&self, client: &C) -> Result<SiteConfiguration, Error>
79 where
80 C: Api + Send,
81 {
82 tracing::debug!(links = ?self.links, "Getting configuration");
83 super::get_content("configuration", &self.links, client).await
84 }
85
86 async fn get_satellite<C>(&self, client: &C) -> Result<Satellite, Error>
87 where
88 C: Api + Send,
89 {
90 super::get_content("satellite", &self.links, client).await
91 }
92
93 async fn get_user<C>(&self, client: &C) -> Result<User, Error>
94 where
95 C: Api + Send,
96 {
97 super::get_content("user", &self.links, client).await
98 }
99}