actor_sample/user_actor/
entity.rs1use crate::model::{User, UserCreate, UserId, UserUpdate};
9use crate::user_actor::UserError;
10use actor_framework::ActorEntity;
11use async_trait::async_trait;
12
13#[derive(Debug)]
14pub enum UserAction {
15 }
17
18#[doc(hidden)]
20#[allow(dead_code)]
23pub const ENTITY_IMPL_PRESENT: bool = true;
24
25#[async_trait]
26impl ActorEntity for User {
27 type Id = UserId;
28 type Create = UserCreate;
29 type Update = UserUpdate;
30 type Action = UserAction;
31 type ActionResult = ();
32 type Context = ();
33 type Error = UserError;
34
35 fn from_create_params(id: UserId, params: UserCreate) -> Result<Self, Self::Error> {
39 Ok(User {
40 id,
41 name: params.name,
42 email: params.email,
43 })
44 }
45
46 async fn on_update(
52 &mut self,
53 update: UserUpdate,
54 _ctx: &Self::Context,
55 ) -> Result<(), Self::Error> {
56 if let Some(name) = update.name {
57 self.name = name;
58 }
59 if let Some(email) = update.email {
60 self.email = email;
61 }
62 Ok(())
63 }
64
65 async fn handle_action(
66 &mut self,
67 _action: UserAction,
68 _ctx: &Self::Context,
69 ) -> Result<(), Self::Error> {
70 Ok(())
71 }
72}