summaryrefslogtreecommitdiff
path: root/makima/src/daemon/api/directive.rs
blob: 42f6f45c76f0b20cb3fe63a82435d0a7589fa3c0 (plain) (blame)
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
//! Directive API methods.

use serde::Serialize;
use uuid::Uuid;

use super::client::{ApiClient, ApiError};
use super::supervisor::JsonValue;

/// Request to update a directive.
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateDirectiveRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<i32>,
}

impl ApiClient {
    /// Get directive status and details.
    pub async fn directive_status(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
        self.get(&format!("/api/v1/directives/{}", directive_id))
            .await
    }

    /// List chains for a directive.
    pub async fn directive_chains(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
        self.get(&format!("/api/v1/directives/{}/chains", directive_id))
            .await
    }

    /// Get a chain with its steps.
    pub async fn directive_chain(
        &self,
        directive_id: Uuid,
        chain_id: Uuid,
    ) -> Result<JsonValue, ApiError> {
        self.get(&format!(
            "/api/v1/directives/{}/chains/{}",
            directive_id, chain_id
        ))
        .await
    }

    /// Update a directive.
    pub async fn directive_update(
        &self,
        directive_id: Uuid,
        req: UpdateDirectiveRequest,
    ) -> Result<JsonValue, ApiError> {
        self.put(&format!("/api/v1/directives/{}", directive_id), &req)
            .await
    }

    /// Start a directive (transition from draft to planning).
    pub async fn directive_start(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
        self.post_empty(&format!("/api/v1/directives/{}/start", directive_id))
            .await
    }
}