Updated account entity for better readability, now Account::get_names always orders by name
This commit is contained in:
@ -30,29 +30,26 @@ impl Entity {
|
||||
user_id: u64,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<impl Stream<Item = crate::Result<Model>> + '_> {
|
||||
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<impl Stream<Item = crate::Result<String>> + '_> {
|
||||
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
|
||||
|
Reference in New Issue
Block a user