|
@ -9,7 +9,7 @@ use libpso::character::{settings, guildcard}; |
|
|
use libpso::util::vec_to_array;
|
|
|
use libpso::util::vec_to_array;
|
|
|
use crate::entity::account::*;
|
|
|
use crate::entity::account::*;
|
|
|
use crate::entity::character::*;
|
|
|
use crate::entity::character::*;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
|
|
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
use crate::entity::item::*;
|
|
|
use crate::entity::item::*;
|
|
|
use super::models::*;
|
|
|
use super::models::*;
|
|
|
|
|
|
|
|
@ -99,30 +99,30 @@ impl PostgresGateway { |
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
#[async_trait::async_trait]
|
|
|
impl EntityGateway for PostgresGateway {
|
|
|
impl EntityGateway for PostgresGateway {
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Option<UserAccountEntity> {
|
|
|
|
|
|
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|
|
let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (email, username, password) values ($1, $2, $3) returning *;")
|
|
|
let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (email, username, password) values ($1, $2, $3) returning *;")
|
|
|
.bind(user.email)
|
|
|
.bind(user.email)
|
|
|
.bind(user.username)
|
|
|
.bind(user.username)
|
|
|
.bind(user.password)
|
|
|
.bind(user.password)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(new_user.into())
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(new_user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_by_id(&self, id: UserAccountId) -> Option<UserAccountEntity> {
|
|
|
|
|
|
|
|
|
async fn get_user_by_id(&self, id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where id = $1")
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where id = $1")
|
|
|
.bind(id.0)
|
|
|
.bind(id.0)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(user.into())
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_by_name(&self, username: String) -> Option<UserAccountEntity> {
|
|
|
|
|
|
|
|
|
async fn get_user_by_name(&self, username: String) -> Result<UserAccountEntity, GatewayError> {
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where username = $1")
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where username = $1")
|
|
|
.bind(username)
|
|
|
.bind(username)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(user.into())
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_user(&mut self, user: &UserAccountEntity) {
|
|
|
|
|
|
|
|
|
async fn save_user(&mut self, user: &UserAccountEntity) -> Result<(), GatewayError> {
|
|
|
sqlx::query("UPDATE user_accounts set name=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
|
|
|
sqlx::query("UPDATE user_accounts set name=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
|
|
|
.bind(&user.username)
|
|
|
.bind(&user.username)
|
|
|
.bind(&user.password)
|
|
|
.bind(&user.password)
|
|
@ -130,10 +130,11 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(&user.muted_until)
|
|
|
.bind(&user.muted_until)
|
|
|
.bind(&user.flags)
|
|
|
.bind(&user.flags)
|
|
|
.bind(&user.id.0)
|
|
|
.bind(&user.id.0)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn create_user_settings(&mut self, settings: NewUserSettingsEntity) -> Option<UserSettingsEntity> {
|
|
|
|
|
|
|
|
|
async fn create_user_settings(&mut self, settings: NewUserSettingsEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|
|
let new_settings = sqlx::query_as::<_, PgUserSettings>("insert into user_settings (user_account, blocked_users, key_config, joystick_config, option_flags, shortcuts, symbol_chats, team_name)
|
|
|
let new_settings = sqlx::query_as::<_, PgUserSettings>("insert into user_settings (user_account, blocked_users, key_config, joystick_config, option_flags, shortcuts, symbol_chats, team_name)
|
|
|
values ($1, $2, $3, $4, $5, $6, $7, $8) returning *;")
|
|
|
values ($1, $2, $3, $4, $5, $6, $7, $8) returning *;")
|
|
|
.bind(settings.user_id.0)
|
|
|
.bind(settings.user_id.0)
|
|
@ -144,18 +145,18 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(settings.settings.shortcuts.to_vec())
|
|
|
.bind(settings.settings.shortcuts.to_vec())
|
|
|
.bind(settings.settings.symbol_chats.to_vec())
|
|
|
.bind(settings.settings.symbol_chats.to_vec())
|
|
|
.bind(settings.settings.team_name.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.team_name.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(new_settings.into())
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(new_settings.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Option<UserSettingsEntity> {
|
|
|
|
|
|
|
|
|
async fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where id = $1")
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where id = $1")
|
|
|
.bind(user.id.0)
|
|
|
.bind(user.id.0)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(settings.into())
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(settings.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) {
|
|
|
|
|
|
|
|
|
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) -> Result<(), GatewayError> {
|
|
|
sqlx::query("update user_settings set blocked_users=$1, key_config=$2, joystick_config=$3, option_flags=$4, shortcuts=$5, symbol_chats=$6, team_name=$7 where id=$8")
|
|
|
sqlx::query("update user_settings set blocked_users=$1, key_config=$2, joystick_config=$3, option_flags=$4, shortcuts=$5, symbol_chats=$6, team_name=$7 where id=$8")
|
|
|
.bind(settings.settings.blocked_users.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.blocked_users.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.bind(&settings.settings.key_config.to_vec())
|
|
|
.bind(&settings.settings.key_config.to_vec())
|
|
@ -165,10 +166,11 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(&settings.settings.symbol_chats.to_vec())
|
|
|
.bind(&settings.settings.symbol_chats.to_vec())
|
|
|
.bind(settings.settings.team_name.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.team_name.to_vec().into_iter().map(|i| i.to_le_bytes().to_vec()).flatten().collect::<Vec<u8>>())
|
|
|
.bind(&settings.id.0)
|
|
|
.bind(&settings.id.0)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Option<CharacterEntity> {
|
|
|
|
|
|
|
|
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
|
|
|
let q = r#"insert into player_character
|
|
|
let q = r#"insert into player_character
|
|
|
(user_account, slot, name, exp, class, section_id, costume, skin, face, head, hair, hair_r, hair_g, hair_b, prop_x, prop_y, techs,
|
|
|
(user_account, slot, name, exp, class, section_id, costume, skin, face, head, hair, hair_r, hair_g, hair_b, prop_x, prop_y, techs,
|
|
|
config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, meseta, bank_meseta, option_flags)
|
|
|
config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, meseta, bank_meseta, option_flags)
|
|
@ -208,28 +210,28 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(char.meseta as i32)
|
|
|
.bind(char.meseta as i32)
|
|
|
.bind(char.bank_meseta as i32)
|
|
|
.bind(char.bank_meseta as i32)
|
|
|
.bind(char.option_flags as i32)
|
|
|
.bind(char.option_flags as i32)
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
sqlx::query("insert into inventory_slots (pchar) values ($1)")
|
|
|
sqlx::query("insert into inventory_slots (pchar) values ($1)")
|
|
|
.bind(character.id)
|
|
|
.bind(character.id)
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
Some(character.into())
|
|
|
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(character.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_characters_by_user(&self, user: &UserAccountEntity) -> [Option<CharacterEntity>; 4] {
|
|
|
|
|
|
|
|
|
async fn get_characters_by_user(&self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
|
|
|
let mut stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by slot")
|
|
|
let mut stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by slot")
|
|
|
.bind(user.id.0)
|
|
|
.bind(user.id.0)
|
|
|
.fetch(&self.pool);
|
|
|
.fetch(&self.pool);
|
|
|
let mut result = [None; 4];
|
|
|
let mut result = [None; 4];
|
|
|
while let Some(character) = stream.try_next().await.unwrap() {
|
|
|
|
|
|
|
|
|
while let Some(character) = stream.try_next().await? {
|
|
|
let index = character.slot as usize;
|
|
|
let index = character.slot as usize;
|
|
|
result[index] = Some(character.into())
|
|
|
result[index] = Some(character.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
result
|
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_character(&mut self, char: &CharacterEntity) {
|
|
|
|
|
|
|
|
|
async fn save_character(&mut self, char: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
let q = r#"update player_character set
|
|
|
let q = r#"update player_character set
|
|
|
user_account=$1, slot=$2, name=$3, exp=$4, class=$5, section_id=$6, costume=$7, skin=$8, face=$9, head=$10, hair=$11, hair_r=$12,
|
|
|
user_account=$1, slot=$2, name=$3, exp=$4, class=$5, section_id=$6, costume=$7, skin=$8, face=$9, head=$10, hair=$11, hair_r=$12,
|
|
|
hair_g=$13, hair_b=$14, prop_x=$15, prop_y=$16, techs=$17, config=$18, infoboard=$19, guildcard=$20, power=$21, mind=$22, def=$23,
|
|
|
hair_g=$13, hair_b=$14, prop_x=$15, prop_y=$16, techs=$17, config=$18, infoboard=$19, guildcard=$20, power=$21, mind=$22, def=$23,
|
|
@ -267,31 +269,33 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(char.meseta as i32)
|
|
|
.bind(char.meseta as i32)
|
|
|
.bind(char.bank_meseta as i32)
|
|
|
.bind(char.bank_meseta as i32)
|
|
|
.bind(char.id.0 as i32)
|
|
|
.bind(char.id.0 as i32)
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> GuildCardDataEntity {
|
|
|
|
|
|
GuildCardDataEntity {
|
|
|
|
|
|
|
|
|
async fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|
|
|
|
|
Ok(GuildCardDataEntity {
|
|
|
id: GuildCardDataId(0),
|
|
|
id: GuildCardDataId(0),
|
|
|
user_id: user.id,
|
|
|
user_id: user.id,
|
|
|
guildcard: guildcard::GuildCardData::default(),
|
|
|
guildcard: guildcard::GuildCardData::default(),
|
|
|
}
|
|
|
|
|
|
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Option<ItemEntity> {
|
|
|
|
|
|
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|
|
|
|
|
let mut tx = self.pool.begin().await?;
|
|
|
let new_item = sqlx::query_as::<_, PgItem>("insert into item (item) values ($1) returning *;")
|
|
|
let new_item = sqlx::query_as::<_, PgItem>("insert into item (item) values ($1) returning *;")
|
|
|
.bind(sqlx::types::Json(PgItemDetail::from(item.item)))
|
|
|
.bind(sqlx::types::Json(PgItemDetail::from(item.item)))
|
|
|
.fetch_one(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.fetch_one(&mut tx).await?;
|
|
|
let location = if let ItemLocation::Inventory{character_id, slot, ..} = &item.location {
|
|
|
let location = if let ItemLocation::Inventory{character_id, slot, ..} = &item.location {
|
|
|
sqlx::query("insert into item_location (item, location) values ($1, $2)")
|
|
|
sqlx::query("insert into item_location (item, location) values ($1, $2)")
|
|
|
.bind(new_item.id)
|
|
|
.bind(new_item.id)
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item.location.clone())))
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item.location.clone())))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
sqlx::query("update inventory_slots set items[$2] = $1 where pchar = $3")
|
|
|
sqlx::query("update inventory_slots set items[$2] = $1 where pchar = $3")
|
|
|
.bind(new_item.id)
|
|
|
.bind(new_item.id)
|
|
|
.bind(*slot as i32)
|
|
|
.bind(*slot as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
sqlx::query_as::<_, PgItemLocation>(r#"select
|
|
|
sqlx::query_as::<_, PgItemLocation>(r#"select
|
|
|
item_location.item,
|
|
|
item_location.item,
|
|
|
jsonb_set(item_location.location, '{Inventory,slot}', (array_position(inventory_slots.items, item.id))::text::jsonb) as location,
|
|
|
jsonb_set(item_location.location, '{Inventory,slot}', (array_position(inventory_slots.items, item.id))::text::jsonb) as location,
|
|
@ -303,70 +307,77 @@ impl EntityGateway for PostgresGateway { |
|
|
order by item_location.created_at
|
|
|
order by item_location.created_at
|
|
|
limit 1"#)
|
|
|
limit 1"#)
|
|
|
.bind(new_item.id)
|
|
|
.bind(new_item.id)
|
|
|
.fetch_one(&self.pool).await.unwrap()
|
|
|
|
|
|
|
|
|
.fetch_one(&mut tx).await?
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
sqlx::query_as::<_, PgItemLocation>("insert into item_location (item, location) values ($1, $2) returning *")
|
|
|
sqlx::query_as::<_, PgItemLocation>("insert into item_location (item, location) values ($1, $2) returning *")
|
|
|
.bind(new_item.id)
|
|
|
.bind(new_item.id)
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item.location)))
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item.location)))
|
|
|
.fetch_one(&self.pool).await.unwrap()
|
|
|
|
|
|
|
|
|
.fetch_one(&mut tx).await?
|
|
|
};
|
|
|
};
|
|
|
Some(ItemEntity {
|
|
|
|
|
|
|
|
|
tx.commit().await?;
|
|
|
|
|
|
Ok(ItemEntity {
|
|
|
id: ItemEntityId(new_item.id as u32),
|
|
|
id: ItemEntityId(new_item.id as u32),
|
|
|
item: new_item.item.0.into(),
|
|
|
item: new_item.item.0.into(),
|
|
|
location: location.location.0.into(),
|
|
|
location: location.location.0.into(),
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) {
|
|
|
|
|
|
|
|
|
async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) -> Result<(), GatewayError> {
|
|
|
|
|
|
let mut tx = self.pool.begin().await?;
|
|
|
if let ItemLocation::Inventory{character_id, slot, ..} = &item_location {
|
|
|
if let ItemLocation::Inventory{character_id, slot, ..} = &item_location {
|
|
|
sqlx::query("update inventory_slots set items[array_position(items, $1)] = null where pchar = $2 and items[array_position(items, $1)] is not null")
|
|
|
sqlx::query("update inventory_slots set items[array_position(items, $1)] = null where pchar = $2 and items[array_position(items, $1)] is not null")
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
sqlx::query("update inventory_slots set items[$2] = $1 where pchar = $3")
|
|
|
sqlx::query("update inventory_slots set items[$2] = $1 where pchar = $3")
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(*slot as i32)
|
|
|
.bind(*slot as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.bind(character_id.0 as i32)
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
sqlx::query(r#"insert into item_location (item, location)
|
|
|
sqlx::query(r#"insert into item_location (item, location)
|
|
|
select $1, $2
|
|
|
select $1, $2
|
|
|
where (select jsonb_object_keys(location) from item_location where item=$1
|
|
|
where (select jsonb_object_keys(location) from item_location where item=$1
|
|
|
order by created_at desc limit 1) != 'Inventory'"#)
|
|
|
order by created_at desc limit 1) != 'Inventory'"#)
|
|
|
.bind(item_id.0)
|
|
|
.bind(item_id.0)
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
sqlx::query("insert into item_location (item, location) values ($1, $2)")
|
|
|
sqlx::query("insert into item_location (item, location) values ($1, $2)")
|
|
|
.bind(item_id.0)
|
|
|
.bind(item_id.0)
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
tx.commit().await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) {
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::FeedMag{food: *tool_item_id})))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::FeedMag{food: *tool_item_id})))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) {
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::OwnerChange(character.char_class, character.section_id))))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::OwnerChange(character.char_class, character.section_id))))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) {
|
|
|
|
|
|
|
|
|
async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(mag_item_id.0)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::MagCell(*mag_cell_id))))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::MagCell(*mag_cell_id))))
|
|
|
.execute(&self.pool).await.unwrap();
|
|
|
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_items_by_character(&self, char: &CharacterEntity) -> Vec<ItemEntity> {
|
|
|
|
|
|
|
|
|
async fn get_items_by_character(&self, char: &CharacterEntity) -> Result<Vec<ItemEntity>, GatewayError> {
|
|
|
let q = r#"select * from (
|
|
|
let q = r#"select * from (
|
|
|
select distinct on (item_location.item)
|
|
|
select distinct on (item_location.item)
|
|
|
item.id,
|
|
|
item.id,
|
|
@ -388,7 +399,7 @@ impl EntityGateway for PostgresGateway { |
|
|
let items = sqlx::query_as::<_, PgItemWithLocation>(q)
|
|
|
let items = sqlx::query_as::<_, PgItemWithLocation>(q)
|
|
|
.bind(char.id.0)
|
|
|
.bind(char.id.0)
|
|
|
.fetch(&self.pool);
|
|
|
.fetch(&self.pool);
|
|
|
join_all(items
|
|
|
|
|
|
|
|
|
Ok(join_all(items
|
|
|
.filter_map(|item: Result<PgItemWithLocation, _>| {
|
|
|
.filter_map(|item: Result<PgItemWithLocation, _>| {
|
|
|
let item = item.ok()?;
|
|
|
let item = item.ok()?;
|
|
|
Some(ItemEntity {
|
|
|
Some(ItemEntity {
|
|
@ -402,6 +413,6 @@ impl EntityGateway for PostgresGateway { |
|
|
})
|
|
|
})
|
|
|
.collect::<Vec<_>>()
|
|
|
.collect::<Vec<_>>()
|
|
|
.await
|
|
|
.await
|
|
|
).await
|
|
|
|
|
|
|
|
|
).await)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|