|
@ -276,17 +276,17 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit |
|
|
|
|
|
|
|
|
async fn get_characters_by_user(conn: &mut sqlx::PgConnection, 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 stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by created_at;")
|
|
|
.bind(user.id.0)
|
|
|
.bind(user.id.0)
|
|
|
.fetch(conn);
|
|
|
.fetch(conn);
|
|
|
const NONE: Option<CharacterEntity> = None;
|
|
|
|
|
|
let mut result = [NONE; 4];
|
|
|
|
|
|
while let Some(character) = stream.try_next().await? {
|
|
|
|
|
|
let index = character.slot as usize;
|
|
|
|
|
|
result[index] = Some(character.into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
|
|
|
|
|
|
Ok(stream.fold(core::array::from_fn(|_| None), |mut acc, char| {
|
|
|
|
|
|
if let Ok(char) = char {
|
|
|
|
|
|
let slot = char.slot as usize;
|
|
|
|
|
|
acc[slot] = Some(char.into())
|
|
|
|
|
|
}
|
|
|
|
|
|
acc
|
|
|
|
|
|
}).await)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) -> Result<(), GatewayError>
|
|
|
async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) -> Result<(), GatewayError>
|
|
|