add gateway function set_character_meseta
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
jake 2021-10-14 00:16:22 -06:00
parent 296d1cc0ea
commit 6ed0d838d2
3 changed files with 21 additions and 0 deletions

View File

@ -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!();
}
}

View File

@ -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(())
}
}

View File

@ -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(())
}
}