Browse Source

add gateway function set_character_meseta

pull/80/head
jake 3 years ago
parent
commit
6ed0d838d2
  1. 4
      src/entity/gateway/entitygateway.rs
  2. 8
      src/entity/gateway/inmemory.rs
  3. 9
      src/entity/gateway/postgres/postgres.rs

4
src/entity/gateway/entitygateway.rs

@ -115,4 +115,8 @@ pub trait EntityGateway: Send + Sync + Clone {
async fn set_character_equips(&mut self, _char_id: &CharacterEntityId, _equips: &EquippedEntity) -> Result<(), GatewayError> {
unimplemented!();
}
async fn set_character_meseta(&mut self, _char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> {
unimplemented!();
}
}

8
src/entity/gateway/inmemory.rs

@ -318,4 +318,12 @@ impl EntityGateway for InMemoryGateway {
equips.insert(*char_id, equipped.clone());
Ok(())
}
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> {
let mut characters = self.characters.lock().unwrap();
if let Some(char) = characters.get_mut(&char_id) {
char.meseta = amount as u32;
}
Ok(())
}
}

9
src/entity/gateway/postgres/postgres.rs

@ -597,4 +597,13 @@ impl EntityGateway for PostgresGateway {
.await?;
Ok(())
}
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> {
sqlx::query(r#"update player_character set meseta=$2 where id = $1"#)
.bind(char_id.0)
.bind(amount as i32)
.execute(&self.pool)
.await?;
Ok(())
}
}
Loading…
Cancel
Save