|
@ -42,8 +42,11 @@ impl PostgresGateway { |
|
|
pool,
|
|
|
pool,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn apply_item_modifications(&self, item: ItemEntity) -> ItemEntity {
|
|
|
|
|
|
|
|
|
async fn apply_item_modifications(conn: &mut sqlx::PgConnection, item: ItemEntity) -> ItemEntity
|
|
|
|
|
|
{
|
|
|
let ItemEntity {id, item} = item;
|
|
|
let ItemEntity {id, item} = item;
|
|
|
|
|
|
|
|
|
let item = match item {
|
|
|
let item = match item {
|
|
@ -54,7 +57,7 @@ impl PostgresGateway { |
|
|
order by created_at"#;
|
|
|
order by created_at"#;
|
|
|
let weapon_modifiers = sqlx::query_as::<_, PgWeaponModifier>(q)
|
|
|
let weapon_modifiers = sqlx::query_as::<_, PgWeaponModifier>(q)
|
|
|
.bind(id.0 as i32)
|
|
|
.bind(id.0 as i32)
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
|
|
|
.fetch(conn);
|
|
|
|
|
|
|
|
|
weapon_modifiers.for_each(|modifier| {
|
|
|
weapon_modifiers.for_each(|modifier| {
|
|
|
if let Ok(modifier) = modifier {
|
|
|
if let Ok(modifier) = modifier {
|
|
@ -72,7 +75,7 @@ impl PostgresGateway { |
|
|
where mag = $1 order by created_at"#;
|
|
|
where mag = $1 order by created_at"#;
|
|
|
let mag_modifiers = sqlx::query_as::<_, PgMagModifierWithParameters>(q)
|
|
|
let mag_modifiers = sqlx::query_as::<_, PgMagModifierWithParameters>(q)
|
|
|
.bind(id.0 as i32)
|
|
|
.bind(id.0 as i32)
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
|
|
|
.fetch(conn);
|
|
|
|
|
|
|
|
|
mag_modifiers.for_each(|modifier| {
|
|
|
mag_modifiers.for_each(|modifier| {
|
|
|
let PgMagModifierWithParameters {modifier, feed, cell, ..} = modifier.unwrap();
|
|
|
let PgMagModifierWithParameters {modifier, feed, cell, ..} = modifier.unwrap();
|
|
@ -103,35 +106,37 @@ impl PostgresGateway { |
|
|
item,
|
|
|
item,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
|
impl EntityGateway for PostgresGateway {
|
|
|
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn create_user(conn: &mut sqlx::PgConnection, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (email, username, password, activated) values ($1, $2, $3, $4) returning *;")
|
|
|
let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (email, username, password, activated) values ($1, $2, $3, $4) returning *;")
|
|
|
.bind(user.email)
|
|
|
.bind(user.email)
|
|
|
.bind(user.username)
|
|
|
.bind(user.username)
|
|
|
.bind(user.password)
|
|
|
.bind(user.password)
|
|
|
.bind(user.activated)
|
|
|
.bind(user.activated)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(new_user.into())
|
|
|
Ok(new_user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_by_id(&self, id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_user_by_id(conn: &mut sqlx::PgConnection, 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?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(user.into())
|
|
|
Ok(user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_by_name(&self, username: String) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_user_by_name(conn: &mut sqlx::PgConnection, 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?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(user.into())
|
|
|
Ok(user.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_user(&mut self, user: &UserAccountEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn save_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query("UPDATE user_accounts set username=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
|
|
|
sqlx::query("UPDATE user_accounts set username=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
|
|
|
.bind(&user.username)
|
|
|
.bind(&user.username)
|
|
|
.bind(&user.password)
|
|
|
.bind(&user.password)
|
|
@ -139,12 +144,13 @@ 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)
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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, keyboard_config, gamepad_config, option_flags, shortcuts, symbol_chats, team_name)
|
|
|
|
|
|
|
|
|
async fn create_user_settings(conn: &mut sqlx::PgConnection, 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)
|
|
|
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)
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
@ -154,19 +160,21 @@ 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.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(new_settings.into())
|
|
|
Ok(new_settings.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_user_settings_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where user_account = $1")
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where user_account = $1")
|
|
|
.bind(user.id.0)
|
|
|
.bind(user.id.0)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(settings.into())
|
|
|
Ok(settings.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
sqlx::query("update user_settings set blocked_users=$1, keyboard_config=$2, gamepad_config=$3, option_flags=$4, shortcuts=$5, symbol_chats=$6, team_name=$7 where id=$8")
|
|
|
|
|
|
|
|
|
async fn save_user_settings(conn: &mut sqlx::PgConnection, 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")
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(&settings.settings.keyboard_config.to_vec())
|
|
|
.bind(&settings.settings.keyboard_config.to_vec())
|
|
|
.bind(&settings.settings.gamepad_config.to_vec())
|
|
|
.bind(&settings.settings.gamepad_config.to_vec())
|
|
@ -175,11 +183,12 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(&settings.settings.symbol_chats.to_vec())
|
|
|
.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.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(&settings.id.0)
|
|
|
.bind(&settings.id.0)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn create_character(conn: &mut sqlx::PgConnection, 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, option_flags)
|
|
|
config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, option_flags)
|
|
@ -216,15 +225,16 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(char.materials.tp as i16)
|
|
|
.bind(char.materials.tp as i16)
|
|
|
.bind(char.tech_menu.tech_menu.to_vec())
|
|
|
.bind(char.tech_menu.tech_menu.to_vec())
|
|
|
.bind(char.option_flags as i32)
|
|
|
.bind(char.option_flags as i32)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
|
|
|
|
|
|
Ok(character.into())
|
|
|
Ok(character.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_characters_by_user(&self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_characters_by_user(conn: &mut sqlx::PgConnection, 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(conn);
|
|
|
const NONE: Option<CharacterEntity> = None;
|
|
|
const NONE: Option<CharacterEntity> = None;
|
|
|
let mut result = [NONE; 4];
|
|
|
let mut result = [NONE; 4];
|
|
|
while let Some(character) = stream.try_next().await? {
|
|
|
while let Some(character) = stream.try_next().await? {
|
|
@ -235,7 +245,8 @@ impl EntityGateway for PostgresGateway { |
|
|
Ok(result)
|
|
|
Ok(result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_character(&mut self, char: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn save_character(conn: &mut sqlx::PgConnection, 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,
|
|
@ -272,143 +283,74 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(char.tech_menu.tech_menu.to_vec())
|
|
|
.bind(char.tech_menu.tech_menu.to_vec())
|
|
|
.bind(char.option_flags as i32)
|
|
|
.bind(char.option_flags as i32)
|
|
|
.bind(char.id.0 as i32)
|
|
|
.bind(char.id.0 as i32)
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|
|
|
|
|
Ok(GuildCardDataEntity {
|
|
|
|
|
|
id: GuildCardDataId(0),
|
|
|
|
|
|
user_id: user.id,
|
|
|
|
|
|
guildcard: guildcard::GuildCardData::default(),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|
|
|
|
|
let mut tx = self.pool.begin().await?;
|
|
|
|
|
|
|
|
|
async fn create_item(conn: &mut sqlx::PgConnection, item: NewItemEntity) -> Result<ItemEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
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(&mut tx).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(conn).await?;
|
|
|
|
|
|
|
|
|
tx.commit().await?;
|
|
|
|
|
|
Ok(ItemEntity {
|
|
|
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(),
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn add_item_note(&mut self, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query("insert into item_note(item, note) values ($1, $2)")
|
|
|
sqlx::query("insert into item_note(item, note) values ($1, $2)")
|
|
|
.bind(item_id.0)
|
|
|
.bind(item_id.0)
|
|
|
.bind(sqlx::types::Json(PgItemNoteDetail::from(item_note)))
|
|
|
.bind(sqlx::types::Json(PgItemNoteDetail::from(item_note)))
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
let mut tx = self.pool.begin().await?;
|
|
|
|
|
|
if let ItemLocation::Inventory{slot, ..} = &item_location {
|
|
|
|
|
|
sqlx::query("delete from inventory_slot where item = $1")
|
|
|
|
|
|
.bind(item_id.0 as i32)
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
|
|
|
sqlx::query("insert into inventory_slot (item, slot) values ($1, $2)")
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(*slot as i32)
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
|
|
|
sqlx::query(r#"insert into item_location (item, location)
|
|
|
|
|
|
select $1, $2
|
|
|
|
|
|
where (select jsonb_object_keys(location) from item_location where item=$1
|
|
|
|
|
|
order by created_at desc limit 1) != 'Inventory'"#)
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
sqlx::query("insert into item_location (item, location) values ($1, $2)")
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(sqlx::types::Json(PgItemLocationDetail::from(item_location)))
|
|
|
|
|
|
.execute(&mut tx).await?;
|
|
|
|
|
|
}
|
|
|
|
|
|
tx.commit().await?;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn feed_mag(conn: &mut sqlx::PgConnection, 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?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(conn: &mut sqlx::PgConnection, 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?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn use_mag_cell(conn: &mut sqlx::PgConnection, 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?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);")
|
|
|
.bind(item_id.0)
|
|
|
.bind(item_id.0)
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
async fn get_items_by_character(&self, char_id: &CharacterEntityId) -> Result<Vec<ItemEntity>, GatewayError> {
|
|
|
|
|
|
let q = r#"select * from (
|
|
|
|
|
|
select distinct on (item_location.item)
|
|
|
|
|
|
item.id,
|
|
|
|
|
|
case
|
|
|
|
|
|
when item_location.location -> 'Inventory' is not null then
|
|
|
|
|
|
jsonb_set(item_location.location, '{Inventory,slot}', inventory_slot.slot::text::jsonb)
|
|
|
|
|
|
else
|
|
|
|
|
|
item_location.location
|
|
|
|
|
|
end,
|
|
|
|
|
|
item.item
|
|
|
|
|
|
from item_location
|
|
|
|
|
|
join item on item.id = item_location.item
|
|
|
|
|
|
join inventory_slot on inventory_slot.item = item.id
|
|
|
|
|
|
order by item_location.item, item_location.created_at desc
|
|
|
|
|
|
) as i
|
|
|
|
|
|
where cast (location -> 'Inventory' ->> 'character_id' as integer) = $1
|
|
|
|
|
|
or cast (location -> 'Bank' ->> 'character_id' as integer) = $1
|
|
|
|
|
|
"#;
|
|
|
|
|
|
let items = sqlx::query_as::<_, PgItemWithLocation>(q)
|
|
|
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
Ok(join_all(items
|
|
|
|
|
|
.filter_map(|item: Result<PgItemWithLocation, _>| {
|
|
|
|
|
|
let item = item.ok()?;
|
|
|
|
|
|
Some(ItemEntity {
|
|
|
|
|
|
id: ItemEntityId(item.id as u32),
|
|
|
|
|
|
item: item.item.0.into(),
|
|
|
|
|
|
location: item.location.0.into()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.map(|item: ItemEntity| {
|
|
|
|
|
|
self.apply_item_modifications(item)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
|
.await
|
|
|
|
|
|
).await)
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_character_inventory(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
|
|
|
let mut t = conn.begin().await?;
|
|
|
let inventory = sqlx::query_as::<_, PgInventoryEntity>("select * from inventory where pchar = $1")
|
|
|
let inventory = sqlx::query_as::<_, PgInventoryEntity>("select * from inventory where pchar = $1")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await?;
|
|
|
|
|
|
|
|
|
// TODO: inefficient
|
|
|
// TODO: inefficient
|
|
|
let mut real_inventory = Vec::new();
|
|
|
let mut real_inventory = Vec::new();
|
|
|
for inv_item in inventory.items.0.into_iter() {
|
|
|
for inv_item in inventory.items.0.into_iter() {
|
|
@ -416,9 +358,9 @@ impl EntityGateway for PostgresGateway { |
|
|
PgInventoryItemEntity::Individual(item) => {
|
|
|
PgInventoryItemEntity::Individual(item) => {
|
|
|
let entity = sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
let entity = sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
.bind(item)
|
|
|
.bind(item)
|
|
|
.fetch_one(&self.pool).await
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| self.apply_item_modifications(item))?
|
|
|
|
|
|
|
|
|
.map(|item| apply_item_modifications(&mut t, item))?
|
|
|
.await;
|
|
|
.await;
|
|
|
real_inventory.push(InventoryItemEntity::Individual(entity));
|
|
|
real_inventory.push(InventoryItemEntity::Individual(entity));
|
|
|
},
|
|
|
},
|
|
@ -427,10 +369,8 @@ impl EntityGateway for PostgresGateway { |
|
|
for s_item in items {
|
|
|
for s_item in items {
|
|
|
stacked_item.push(sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
stacked_item.push(sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
.bind(s_item)
|
|
|
.bind(s_item)
|
|
|
.fetch_one(&self.pool).await
|
|
|
|
|
|
.map(|item| item.into())
|
|
|
|
|
|
.map(|item| self.apply_item_modifications(item))?
|
|
|
|
|
|
.await)
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await
|
|
|
|
|
|
.map(|item| item.into())?)
|
|
|
}
|
|
|
}
|
|
|
real_inventory.push(InventoryItemEntity::Stacked(stacked_item));
|
|
|
real_inventory.push(InventoryItemEntity::Stacked(stacked_item));
|
|
|
}
|
|
|
}
|
|
@ -440,11 +380,13 @@ impl EntityGateway for PostgresGateway { |
|
|
Ok(InventoryEntity::new(real_inventory))
|
|
|
Ok(InventoryEntity::new(real_inventory))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: BankName) -> Result<BankEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank_name: BankName) -> Result<BankEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
|
|
|
let mut t = conn.begin().await?;
|
|
|
let bank = sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1 and name = $2")
|
|
|
let bank = sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1 and name = $2")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(bank_name.0)
|
|
|
.bind(bank_name.0)
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await?;
|
|
|
// TODO: inefficient
|
|
|
// TODO: inefficient
|
|
|
let mut real_bank = Vec::new();
|
|
|
let mut real_bank = Vec::new();
|
|
|
for bank_item in bank.items.0.into_iter() {
|
|
|
for bank_item in bank.items.0.into_iter() {
|
|
@ -452,9 +394,9 @@ impl EntityGateway for PostgresGateway { |
|
|
PgInventoryItemEntity::Individual(item) => {
|
|
|
PgInventoryItemEntity::Individual(item) => {
|
|
|
let entity = sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
let entity = sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
.bind(item)
|
|
|
.bind(item)
|
|
|
.fetch_one(&self.pool).await
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| self.apply_item_modifications(item))?
|
|
|
|
|
|
|
|
|
.map(|item| apply_item_modifications(&mut t, item))?
|
|
|
.await;
|
|
|
.await;
|
|
|
real_bank.push(BankItemEntity::Individual(entity));
|
|
|
real_bank.push(BankItemEntity::Individual(entity));
|
|
|
},
|
|
|
},
|
|
@ -463,9 +405,9 @@ impl EntityGateway for PostgresGateway { |
|
|
for s_item in items {
|
|
|
for s_item in items {
|
|
|
stacked_item.push(sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
stacked_item.push(sqlx::query_as::<_, PgItemEntity>("select item.id, item.item from item where id = $1")
|
|
|
.bind(s_item)
|
|
|
.bind(s_item)
|
|
|
.fetch_one(&self.pool).await
|
|
|
|
|
|
|
|
|
.fetch_one(&mut t).await
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| item.into())
|
|
|
.map(|item| self.apply_item_modifications(item))?
|
|
|
|
|
|
|
|
|
.map(|item| apply_item_modifications(&mut t, item))?
|
|
|
.await)
|
|
|
.await)
|
|
|
}
|
|
|
}
|
|
|
real_bank.push(BankItemEntity::Stacked(stacked_item));
|
|
|
real_bank.push(BankItemEntity::Stacked(stacked_item));
|
|
@ -476,7 +418,8 @@ impl EntityGateway for PostgresGateway { |
|
|
Ok(BankEntity::new(real_bank))
|
|
|
Ok(BankEntity::new(real_bank))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn set_character_inventory(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
let inventory = inventory.items.iter()
|
|
|
let inventory = inventory.items.iter()
|
|
|
.map(|item| {
|
|
|
.map(|item| {
|
|
|
match item {
|
|
|
match item {
|
|
@ -493,12 +436,13 @@ impl EntityGateway for PostgresGateway { |
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|
.execute(&self.pool)
|
|
|
|
|
|
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
let bank = bank.items.iter()
|
|
|
let bank = bank.items.iter()
|
|
|
.map(|item| {
|
|
|
.map(|item| {
|
|
|
match item {
|
|
|
match item {
|
|
@ -516,21 +460,23 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.bind(bank_name.0)
|
|
|
.bind(bank_name.0)
|
|
|
.execute(&self.pool)
|
|
|
|
|
|
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_character_equips(&mut self, char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_character_equips(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError>
|
|
|
|
|
|
{
|
|
|
let equips = sqlx::query_as::<_, PgEquipped>("select * from equipped where pchar = $1")
|
|
|
let equips = sqlx::query_as::<_, PgEquipped>("select * from equipped where pchar = $1")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.fetch_one(&self.pool)
|
|
|
|
|
|
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
Ok(equips.into())
|
|
|
Ok(equips.into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_character_equips(&mut self, char_id: &CharacterEntityId, equips: &EquippedEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn set_character_equips(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, equips: &EquippedEntity) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query(r#"insert into equipped (pchar, weapon, armor, shield, unit0, unit1, unit2, unit3, mag) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
|
sqlx::query(r#"insert into equipped (pchar, weapon, armor, shield, unit0, unit1, unit2, unit3, mag) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
|
on conflict (pchar) do update set weapon=$2, armor=$3, shield=$4, unit0=$5, unit1=$6, unit2=$7, unit3=$8, mag=$9"#)
|
|
|
on conflict (pchar) do update set weapon=$2, armor=$3, shield=$4, unit0=$5, unit1=$6, unit2=$7, unit3=$8, mag=$9"#)
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
@ -542,48 +488,168 @@ impl EntityGateway for PostgresGateway { |
|
|
.bind(equips.unit[2].map(|i| i.0 as i32))
|
|
|
.bind(equips.unit[2].map(|i| i.0 as i32))
|
|
|
.bind(equips.unit[3].map(|i| i.0 as i32))
|
|
|
.bind(equips.unit[3].map(|i| i.0 as i32))
|
|
|
.bind(equips.mag.map(|i| i.0 as i32))
|
|
|
.bind(equips.mag.map(|i| i.0 as i32))
|
|
|
.execute(&self.pool)
|
|
|
|
|
|
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn set_character_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.execute(&self.pool)
|
|
|
|
|
|
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_character_meseta(&mut self, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_character_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError>
|
|
|
|
|
|
{
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
struct PgMeseta(i32);
|
|
|
struct PgMeseta(i32);
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1"#)
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1"#)
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.fetch_one(&self.pool)
|
|
|
|
|
|
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
|
|
|
|
|
async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError>
|
|
|
|
|
|
{
|
|
|
sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set items = $2")
|
|
|
sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(bank.0)
|
|
|
.bind(bank.0)
|
|
|
.execute(&self.pool)
|
|
|
|
|
|
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError> {
|
|
|
|
|
|
|
|
|
async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError>
|
|
|
|
|
|
{
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
struct PgMeseta(i32);
|
|
|
struct PgMeseta(i32);
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1 and bank = $2"#)
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1 and bank = $2"#)
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(bank.0)
|
|
|
.bind(bank.0)
|
|
|
.fetch_one(&self.pool)
|
|
|
|
|
|
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
|
impl EntityGateway for PostgresGateway {
|
|
|
|
|
|
async fn create_user(&mut self, user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
create_user(&mut *self.pool.acquire().await?, user).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_user_by_id(&mut self, id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
get_user_by_id(&mut *self.pool.acquire().await?, id).await
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_user_by_name(&mut self, username: String) -> Result<UserAccountEntity, GatewayError> {
|
|
|
|
|
|
get_user_by_name(&mut *self.pool.acquire().await?, username).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn save_user(&mut self, user: &UserAccountEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
save_user(&mut *self.pool.acquire().await?, user).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_user_settings(&mut self, settings: NewUserSettingsEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|
|
|
|
|
create_user_settings(&mut *self.pool.acquire().await?, settings).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_user_settings_by_user(&mut self, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|
|
|
|
|
get_user_settings_by_user(&mut *self.pool.acquire().await?, user).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn save_user_settings(&mut self, settings: &UserSettingsEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
save_user_settings(&mut *self.pool.acquire().await?, settings).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
|
|
|
|
|
|
create_character(&mut *self.pool.acquire().await?, char).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_characters_by_user(&mut self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
|
|
|
|
|
|
get_characters_by_user(&mut *self.pool.acquire().await?, user).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn save_character(&mut self, char: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
save_character(&mut *self.pool.acquire().await?, char).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_guild_card_data_by_user(&mut self, user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|
|
|
|
|
Ok(GuildCardDataEntity {
|
|
|
|
|
|
id: GuildCardDataId(0),
|
|
|
|
|
|
user_id: user.id,
|
|
|
|
|
|
guildcard: guildcard::GuildCardData::default(),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_item(&mut self, item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|
|
|
|
|
create_item(&mut *self.pool.acquire().await?, item).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_item_note(&mut self, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError> {
|
|
|
|
|
|
add_item_note(&mut *self.pool.acquire().await?, item_id, item_note).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
|
|
|
feed_mag(&mut *self.pool.acquire().await?, mag_item_id, tool_item_id).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
change_mag_owner(&mut *self.pool.acquire().await?, mag_item_id, character).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|
|
|
|
|
use_mag_cell(&mut *self.pool.acquire().await?, mag_item_id, mag_cell_id).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
add_weapon_modifier(&mut *self.pool.acquire().await?, item_id, modifier).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
|
|
|
|
|
get_character_inventory(&mut *self.pool.acquire().await?, char_id).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: BankName) -> Result<BankEntity, GatewayError> {
|
|
|
|
|
|
get_character_bank(&mut *self.pool.acquire().await?, char_id, bank_name).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
set_character_inventory(&mut *self.pool.acquire().await?, char_id, inventory).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError> {
|
|
|
|
|
|
set_character_bank(&mut *self.pool.acquire().await?, char_id, bank, bank_name).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_character_equips(&mut self, char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError> {
|
|
|
|
|
|
get_character_equips(&mut *self.pool.acquire().await?, char_id).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_character_equips(&mut self, char_id: &CharacterEntityId, equips: &EquippedEntity) -> Result<(), GatewayError> {
|
|
|
|
|
|
set_character_equips(&mut *self.pool.acquire().await?, char_id, equips).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
|
|
set_character_meseta(&mut *self.pool.acquire().await?, char_id, meseta).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_character_meseta(&mut self, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> {
|
|
|
|
|
|
get_character_meseta(&mut *self.pool.acquire().await?, char_id).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
|
|
set_bank_meseta(&mut *self.pool.acquire().await?, char_id, bank, meseta).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError> {
|
|
|
|
|
|
get_bank_meseta(&mut *self.pool.acquire().await?, char_id, bank).await
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|