freedom_api/extensions/
task.rs

1use 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<<C as Api>::Container<TaskRequest>, Error>> + Send
17    where
18        C: Api + Send;
19
20    fn get_config<C>(
21        &self,
22        client: &C,
23    ) -> impl Future<Output = Result<<C as Api>::Container<SiteConfiguration>, Error>> + Send
24    where
25        C: Api + Send;
26
27    fn get_azel<C>(
28        &self,
29        client: &C,
30    ) -> impl Future<Output = Result<<C as Api>::Container<AzEl>, Error>> + Send
31    where
32        C: Api + Send;
33}
34
35impl TaskExt for Task {
36    fn get_id(&self) -> Result<i32, Error> {
37        super::get_id("self", &self.links)
38    }
39
40    async fn get_task_request<C>(
41        &self,
42        client: &C,
43    ) -> Result<<C as Api>::Container<TaskRequest>, Error>
44    where
45        C: Api,
46    {
47        super::get_item("taskRequest", &self.links, client).await
48    }
49
50    async fn get_config<C>(
51        &self,
52        client: &C,
53    ) -> Result<<C as Api>::Container<SiteConfiguration>, Error>
54    where
55        C: Api + Send + Sync,
56    {
57        super::get_item("config", &self.links, client).await
58    }
59
60    async fn get_azel<C>(&self, client: &C) -> Result<<C as Api>::Container<AzEl>, Error>
61    where
62        C: Api + Send + Sync,
63    {
64        super::get_item("azel", &self.links, client).await
65    }
66}