pick the newest character for a slot when recreating
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		
							parent
							
								
									8157db4c69
								
							
						
					
					
						commit
						aa019d4ea9
					
				@ -0,0 +1,2 @@
 | 
			
		||||
alter table player_character
 | 
			
		||||
  add created_at timestamptz default current_timestamp not null;
 | 
			
		||||
@ -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>
 | 
			
		||||
{
 | 
			
		||||
    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)
 | 
			
		||||
        .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>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user