Skip to main content

cognite/dto/data_modeling/
spaces.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{to_query, IntoParams, LimitCursorQuery, SetCursor};
5#[skip_serializing_none]
6#[derive(Serialize, Deserialize, Clone, Debug, Default)]
7#[serde(rename_all = "camelCase")]
8/// Object used to create a space.
9pub struct SpaceCreate {
10    /// Space ID, must be unique. Note that a few spaces are reserved:
11    ///
12    /// `space`, `cdf`, `dms`, `pg3`, `shared`, `system`, `node`, `edge`.
13    pub space: String,
14    /// Space description.
15    pub description: Option<String>,
16    /// Human readable space name.
17    pub name: Option<String>,
18}
19
20#[skip_serializing_none]
21#[derive(Serialize, Deserialize, Clone, Debug, Default)]
22#[serde(rename_all = "camelCase")]
23/// Description of a data modeling space.
24pub struct Space {
25    /// Space ID, must be unique.
26    pub space: String,
27    /// Space description.
28    pub description: Option<String>,
29    /// Human readable space name.
30    pub name: Option<String>,
31    /// Time this space was created, in milliseconds since epoch.
32    pub created_time: i64,
33    /// Time this space was last modified, in milliseconds since epoch.
34    pub last_updated_time: i64,
35    /// Whether this space is a global space.
36    pub is_global: bool,
37}
38
39#[derive(Default, Clone, Debug)]
40/// Query for listing spaces.
41pub struct SpaceQuery {
42    /// Maximum number of spaces in the result.
43    pub limit: Option<i32>,
44    /// Optional cursor for pagination.
45    pub cursor: Option<String>,
46    /// Include global spaces.
47    pub include_global: Option<bool>,
48}
49
50impl IntoParams for SpaceQuery {
51    fn into_params(self) -> Vec<(String, String)> {
52        let mut params = Vec::new();
53        to_query("limit", &self.limit, &mut params);
54        to_query("cursor", &self.cursor, &mut params);
55        to_query("includeGlobal", &self.include_global, &mut params);
56        params
57    }
58}
59
60impl SetCursor for SpaceQuery {
61    fn set_cursor(&mut self, cursor: Option<String>) {
62        self.cursor = cursor;
63    }
64}
65
66impl From<LimitCursorQuery> for SpaceQuery {
67    fn from(q: LimitCursorQuery) -> Self {
68        Self {
69            limit: q.limit,
70            cursor: q.cursor,
71            include_global: None,
72        }
73    }
74}