pub async fn get_list_champions(
ctx: ApplicationContext<'_, Data, Box<dyn Error + Send + Sync>>,
role: Option<Role>,
) -> Result<Vec<ChampionData>, Box<dyn Error + Send + Sync>>Expand description
⚙️ Retrieves a list of champions from the database, optionally filtered by role.
This asynchronous function queries the MongoDB collection of champions to retrieve either all champions or those matching a specific role. If a role is provided, the function will filter the list accordingly. If no role is specified, all champions will be retrieved.
§Parameters:
ctx: The command context, providing access to the bot’s data and other utilities.role: An optionalRoleenum to filter the champions by role. IfNone, all champions are retrieved.
§Returns:
Result<Vec<ChampionData>, Error>: On success, returns a vector ofChampionDataobjects representing the champions that match the criteria. On failure, returns anErrorindicating what went wrong during the database query.
§Example:
let champions_list = get_list_champions(ctx, Some(Role::MIDLANE)).await?;
for champion in champions_list {
println!("Champion: {}", champion.name);
}§⚠️ Notes:
- If
roleisNone, the function callsget_champions_with_no_roleto retrieve all champions. - If
roleis provided,match_role_with_database_rolesis used to convert theRoleenum to a string, andget_champions_by_roleis called to perform the filtered search. - This function interacts with MongoDB asynchronously and relies on other helper functions for specific queries.
§Related Functions:
get_champions_with_no_role: Retrieves all champions without filtering by role.get_champions_by_role: Retrieves champions filtered by a specific role from the collection.match_role_with_database_roles: Converts aRoleenum into the corresponding string representation.
§Dependencies:
- Requires access to a MongoDB collection (
champions_data) for champion information. - The function depends on other helper functions for querying the MongoDB collection.