@@ -157,7 +157,7 @@ fn validate_context(ctx: &Context) -> Result<(), BoxError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_actor(_context_id: u32, actor: &Actor) -> Result<(), BoxError> {
|
||||
fn validate_actor(actor: &Actor) -> Result<(), BoxError> {
|
||||
let v = as_json(actor)?;
|
||||
let id = json_get_u32(&v, "id")?;
|
||||
if id == 0 {
|
||||
@@ -344,17 +344,17 @@ impl AppService {
|
||||
// -----------------------------
|
||||
// Actor
|
||||
// -----------------------------
|
||||
pub async fn create_actor(&self, context_id: u32, actor: Actor) -> Result<Actor, BoxError> {
|
||||
validate_actor(context_id, &actor)?;
|
||||
pub async fn create_actor(&self, actor: Actor) -> Result<Actor, BoxError> {
|
||||
validate_actor(&actor)?;
|
||||
let v = as_json(&actor)?;
|
||||
let id = json_get_u32(&v, "id")?;
|
||||
self.ensure_actor_not_exists(context_id, id).await?;
|
||||
self.redis.save_actor(context_id, &actor).await?;
|
||||
self.ensure_actor_not_exists_global(id).await?;
|
||||
self.redis.save_actor_global(&actor).await?;
|
||||
Ok(actor)
|
||||
}
|
||||
|
||||
pub async fn load_actor(&self, context_id: u32, id: u32) -> Result<Actor, BoxError> {
|
||||
let actor = self.redis.load_actor(context_id, id).await?;
|
||||
pub async fn load_actor(&self, id: u32) -> Result<Actor, BoxError> {
|
||||
let actor = self.redis.load_actor_global(id).await?;
|
||||
Ok(actor)
|
||||
}
|
||||
|
||||
@@ -1023,8 +1023,8 @@ impl AppService {
|
||||
}
|
||||
}
|
||||
|
||||
async fn ensure_actor_not_exists(&self, db: u32, id: u32) -> Result<(), BoxError> {
|
||||
match self.redis.load_actor(db, id).await {
|
||||
async fn ensure_actor_not_exists_global(&self, id: u32) -> Result<(), BoxError> {
|
||||
match self.redis.load_actor_global(id).await {
|
||||
Ok(_) => Err(Box::new(AlreadyExistsError {
|
||||
key: format!("actor:{}", id),
|
||||
})),
|
||||
|
Reference in New Issue
Block a user