canic_core/api/placement/
binding.rs1use crate::{
2 cdk::types::Principal,
3 dto::{
4 error::Error,
5 placement::binding::{
6 PlacementBindingRecoveryResponse, PlacementBindingRegistryResponse,
7 PlacementBindingStatusResponse,
8 },
9 },
10 workflow::placement::binding::{PlacementBindingWorkflow, query::PlacementBindingQuery},
11};
12
13pub struct PlacementBindingApi;
18
19impl PlacementBindingApi {
20 #[must_use]
21 pub fn lookup_key(pool: &str, key_value: &str) -> Option<Principal> {
22 PlacementBindingQuery::lookup_key(pool, key_value)
23 }
24
25 #[must_use]
26 pub fn lookup_entry(pool: &str, key_value: &str) -> Option<PlacementBindingStatusResponse> {
27 PlacementBindingQuery::lookup_entry(pool, key_value)
28 }
29
30 pub async fn recover_entry(
31 pool: &str,
32 key_value: impl AsRef<str>,
33 ) -> Result<PlacementBindingRecoveryResponse, Error> {
34 PlacementBindingWorkflow::recover_entry(pool, key_value.as_ref())
35 .await
36 .map_err(Error::from)
37 }
38
39 pub async fn resolve_or_create(
40 pool: &str,
41 key_value: impl AsRef<str>,
42 ) -> Result<PlacementBindingStatusResponse, Error> {
43 PlacementBindingWorkflow::resolve_or_create(pool, key_value.as_ref())
44 .await
45 .map_err(Error::from)
46 }
47
48 pub fn bind_instance(
49 pool: &str,
50 key_value: impl AsRef<str>,
51 pid: Principal,
52 ) -> Result<(), Error> {
53 PlacementBindingWorkflow::bind_instance(pool, key_value.as_ref(), pid).map_err(Error::from)
54 }
55
56 #[must_use]
57 pub fn registry() -> PlacementBindingRegistryResponse {
58 PlacementBindingQuery::registry()
59 }
60}