Browse Source

fix some user setting entity stuff

pull/127/head
jake 2 years ago
parent
commit
f09c73611f
  1. 10
      src/entity/gateway/inmemory.rs
  2. 5
      src/entity/gateway/postgres/postgres.rs

10
src/entity/gateway/inmemory.rs

@ -72,6 +72,10 @@ impl EntityGateway for InMemoryGatewayTransaction {
}
}
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) -> Result<(), GatewayError> {
self.original_gateway.save_user_settings(settings).await
}
async fn save_character(&mut self, char: &CharacterEntity) -> Result<(), GatewayError> {
copy_if_needed(&mut *self.working_gateway.characters.lock().await,
&*self.original_gateway.characters.lock().await,
@ -418,6 +422,12 @@ impl EntityGateway for InMemoryGateway {
.ok_or(GatewayError::Error)
}
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) -> Result<(), GatewayError> {
let mut user_settings = self.user_settings.lock().await;
user_settings.insert(settings.id, settings.clone());
Ok(())
}
async fn get_characters_by_user(&mut self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
let characters = self.characters.lock().await;
const NONE: Option<CharacterEntity> = None;

5
src/entity/gateway/postgres/postgres.rs

@ -217,7 +217,7 @@ async fn save_user_settings(conn: &mut sqlx::PgConnection, settings: &UserSettin
.bind(&settings.settings.symbol_chats.to_vec())
.bind(settings.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
.bind(settings.id.0)
.fetch_one(conn).await?;
.execute(conn).await?;
Ok(())
}
@ -236,8 +236,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit
$11, $12, $13, $14, $15,
$16, $17, $18, $19, $20,
$21, $22, $23, $24, $25,
$26, $27, $28, $29, $30,
$31, $32)
$26, $27, $28, $29, $30)
returning *;"#;
let character = sqlx::query_as::<_, PgCharacter>(q)
.bind(char.user_id.0)

Loading…
Cancel
Save