diff --git a/entity/src/account.rs b/entity/src/account.rs index eecfdc1..5edc8b5 100644 --- a/entity/src/account.rs +++ b/entity/src/account.rs @@ -30,29 +30,26 @@ impl Entity { user_id: u64, db: &DatabaseConnection, ) -> crate::Result> + '_> { - let result = Self::find() + Self::find() .filter(Column::UserId.eq(user_id)) .stream(db) - .await?; - Ok(result) + .await } - /// Gets a list of account names of a user + /// Streams the names of the user accounts #[inline] pub async fn get_names( user_id: u64, db: &DatabaseConnection, - ordered: bool, ) -> crate::Result> + '_> { - let mut select = Self::find() + Self::find() .select_only() .column(Column::Name) - .filter(Column::UserId.eq(user_id)); - if ordered { - select = select.order_by_asc(Column::Name); - } - let result = select.into_tuple().stream(db).await?; - Ok(result) + .filter(Column::UserId.eq(user_id)) + .order_by_asc(Column::Name) + .into_tuple() + .stream(db) + .await } /// Checks if the account exists @@ -81,7 +78,6 @@ impl Entity { Self::find_by_id((user_id, account_name.into())) .one(db) .await - .map_err(Into::into) } /// Deletes all the user's accounts from DB diff --git a/src/commands/get_accounts.rs b/src/commands/get_accounts.rs index 3eaaa5a..d5000b6 100644 --- a/src/commands/get_accounts.rs +++ b/src/commands/get_accounts.rs @@ -12,7 +12,7 @@ pub async fn get_accounts( db: DatabaseConnection, ) -> crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - let mut account_names = Account::get_names(user_id, &db, true).await?; + let mut account_names = Account::get_names(user_id, &db).await?; let mut text = match account_names.try_next().await? { Some(name) => format!("Accounts:\n`{name}`"), None => { diff --git a/src/markups.rs b/src/markups.rs index a77d571..160273d 100644 --- a/src/markups.rs +++ b/src/markups.rs @@ -9,7 +9,7 @@ pub async fn account_markup( user_id: u64, db: &DatabaseConnection, ) -> crate::Result { - let account_names: Vec> = Account::get_names(user_id, db, true) + let account_names: Vec> = Account::get_names(user_id, db) .await? .map_ok(KeyboardButton::new) .try_chunks(3)