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>(&self, client: &C) -> impl Future<Output = Result<Task, Error>> + Send + Sync
16 where
17 C: Api;
18
19 fn get_site<C>(&self, client: &C) -> impl Future<Output = Result<Site, Error>> + Send + Sync
20 where
21 C: Api;
22
23 fn get_target_bands<C>(
24 &self,
25 client: &C,
26 ) -> impl Future<Output = Result<Vec<Band>, Error>> + Send + Sync
27 where
28 C: Api;
29
30 fn get_site_configuration<C>(
31 &self,
32 client: &C,
33 ) -> impl Future<Output = Result<SiteConfiguration, Error>> + Send + Sync
34 where
35 C: Api;
36
37 fn get_satellite<C>(
38 &self,
39 client: &C,
40 ) -> impl Future<Output = Result<Satellite, Error>> + Send + Sync
41 where
42 C: Api;
43
44 fn get_user<C>(&self, client: &C) -> impl Future<Output = Result<User, Error>> + Send + Sync
45 where
46 C: Api;
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<Task, Error>
55 where
56 C: Api,
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,
64 {
65 super::get_content("site", &self.links, client).await
66 }
67
68 async fn get_target_bands<C>(&self, client: &C) -> Result<Vec<Band>, Error>
69 where
70 C: Api,
71 {
72 super::get_embedded("targetBands", &self.links, client).await
73 }
74
75 async fn get_site_configuration<C>(&self, client: &C) -> Result<SiteConfiguration, Error>
76 where
77 C: Api,
78 {
79 tracing::debug!(links = ?self.links, "Getting configuration");
80 super::get_content("configuration", &self.links, client).await
81 }
82
83 async fn get_satellite<C>(&self, client: &C) -> Result<Satellite, Error>
84 where
85 C: Api,
86 {
87 super::get_content("satellite", &self.links, client).await
88 }
89
90 async fn get_user<C>(&self, client: &C) -> Result<User, Error>
91 where
92 C: Api,
93 {
94 super::get_content("user", &self.links, client).await
95 }
96}