cognite/api/data_modeling/
containers.rs

1use crate::{
2    dto::data_modeling::containers::{
3        ContainerComponentId, ContainerCreate, ContainerDefinition, ContainerQuery,
4    },
5    models::ItemId,
6    Create, DeleteWithResponse, Items, ItemsVec, List, Resource, Result, Retrieve, WithBasePath,
7};
8
9/// A container represents a bag of properties, each property has a type.
10/// Containers can have indexes, constraints, and default values.
11pub type ContainersResource = Resource<ContainerDefinition>;
12
13impl WithBasePath for ContainersResource {
14    const BASE_PATH: &'static str = "models/containers";
15}
16
17impl Create<ContainerCreate, ContainerDefinition> for ContainersResource {}
18impl DeleteWithResponse<ItemId, ItemId> for ContainersResource {}
19impl List<ContainerQuery, ContainerDefinition> for ContainersResource {}
20impl Retrieve<ItemId, ContainerDefinition> for ContainersResource {}
21
22impl ContainersResource {
23    /// Delete constraints from a container.
24    ///
25    /// # Arguments
26    ///
27    /// * `items` - IDs of container constraints to delete.
28    pub async fn delete_constraints(
29        &self,
30        items: &[ContainerComponentId],
31    ) -> Result<Vec<ContainerComponentId>> {
32        let r: ItemsVec<ContainerComponentId> = self
33            .api_client
34            .post(
35                &format!("{}/constraints/delete", Self::BASE_PATH),
36                &Items::new(items),
37            )
38            .await?;
39        Ok(r.items)
40    }
41
42    /// Delete indexes from a container.
43    ///
44    /// # Arguments
45    ///
46    /// * `items` - IDs of container indexes to delete.
47    pub async fn delete_indexes(
48        &self,
49        items: &[ContainerComponentId],
50    ) -> Result<Vec<ContainerComponentId>> {
51        let r: ItemsVec<ContainerComponentId> = self
52            .api_client
53            .post(
54                &format!("{}/indexes/delete", Self::BASE_PATH),
55                &Items::new(items),
56            )
57            .await?;
58        Ok(r.items)
59    }
60}