freedom_api/extensions/
task.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::future::Future;

use crate::{api::Api, error::Error};
use freedom_models::{
    azel::AzEl,
    site::SiteConfiguration,
    task::{Task, TaskRequest},
};

pub trait TaskExt {
    fn get_id(&self) -> Result<i32, Error>;

    fn get_task_request<C>(
        &self,
        client: &C,
    ) -> impl Future<Output = Result<<C as Api>::Container<TaskRequest>, Error>> + Send
    where
        C: Api + Send;

    fn get_config<C>(
        &self,
        client: &C,
    ) -> impl Future<Output = Result<<C as Api>::Container<SiteConfiguration>, Error>> + Send
    where
        C: Api + Send;

    fn get_azel<C>(
        &self,
        client: &C,
    ) -> impl Future<Output = Result<<C as Api>::Container<AzEl>, Error>> + Send
    where
        C: Api + Send;
}

impl TaskExt for Task {
    fn get_id(&self) -> Result<i32, Error> {
        super::get_id("self", &self.links)
    }

    async fn get_task_request<C>(
        &self,
        client: &C,
    ) -> Result<<C as Api>::Container<TaskRequest>, Error>
    where
        C: Api,
    {
        super::get_item("taskRequest", &self.links, client).await
    }

    async fn get_config<C>(
        &self,
        client: &C,
    ) -> Result<<C as Api>::Container<SiteConfiguration>, Error>
    where
        C: Api + Send + Sync,
    {
        super::get_item("config", &self.links, client).await
    }

    async fn get_azel<C>(&self, client: &C) -> Result<<C as Api>::Container<AzEl>, Error>
    where
        C: Api + Send + Sync,
    {
        super::get_item("azel", &self.links, client).await
    }
}