actor_sample/clients/
user_client.rs1use crate::model::{User, UserCreate, UserId, UserUpdate};
6use crate::user_actor::UserError;
7use actor_framework::ActorClient;
8use actor_framework::{FrameworkError, ResourceClient};
9use async_trait::async_trait;
10use tracing::{debug, instrument};
11
12#[derive(Clone)]
14pub struct UserClient {
15 inner: ResourceClient<User>,
16}
17
18impl UserClient {
19 pub fn new(inner: ResourceClient<User>) -> Self {
20 Self { inner }
21 }
22}
23
24#[async_trait]
25impl ActorClient<User> for UserClient {
26 type Error = UserError;
27
28 fn inner(&self) -> &ResourceClient<User> {
29 &self.inner
30 }
31
32 fn map_error(e: FrameworkError) -> Self::Error {
33 UserError::ActorCommunicationError(e.to_string())
34 }
35}
36
37impl UserClient {
38 #[instrument(skip(self))]
41 pub async fn create_user(&self, params: UserCreate) -> Result<UserId, UserError> {
42 debug!("Sending request");
43 self.inner
44 .create(params)
45 .await
46 .map_err(|e| UserError::ActorCommunicationError(e.to_string()))
47 }
48
49 #[instrument(skip(self))]
51 #[allow(dead_code)]
52 pub async fn update_user(&self, id: UserId, update: UserUpdate) -> Result<User, UserError> {
53 debug!("Sending request");
54 self.inner
55 .update(id, update)
56 .await
57 .map_err(|e| UserError::ActorCommunicationError(e.to_string()))
58 }
59}