freedom_api/extensions/
task.rs1use std::future::Future;
2
3use crate::{api::Api, error::Error};
4use freedom_models::{
5 azel::AzEl,
6 site::SiteConfiguration,
7 task::{Task, TaskRequest},
8};
9
10pub trait TaskExt {
11 fn get_id(&self) -> Result<i32, Error>;
12
13 fn get_task_request<C>(
14 &self,
15 client: &C,
16 ) -> impl Future<Output = Result<TaskRequest, Error>> + Send + Sync
17 where
18 C: Api;
19
20 fn get_site_configuration<C>(
21 &self,
22 client: &C,
23 ) -> impl Future<Output = Result<SiteConfiguration, Error>> + Send + Sync
24 where
25 C: Api;
26
27 fn get_azel<C>(&self, client: &C) -> impl Future<Output = Result<AzEl, Error>> + Send + Sync
28 where
29 C: Api;
30}
31
32impl TaskExt for Task {
33 fn get_id(&self) -> Result<i32, Error> {
34 super::get_id("self", &self.links)
35 }
36
37 async fn get_task_request<C>(&self, client: &C) -> Result<TaskRequest, Error>
38 where
39 C: Api,
40 {
41 super::get_item("taskRequest", &self.links, client).await
42 }
43
44 async fn get_site_configuration<C>(&self, client: &C) -> Result<SiteConfiguration, Error>
45 where
46 C: Api,
47 {
48 super::get_item("config", &self.links, client).await
49 }
50
51 async fn get_azel<C>(&self, client: &C) -> Result<AzEl, Error>
52 where
53 C: Api,
54 {
55 super::get_item("azel", &self.links, client).await
56 }
57}