Now checking that account exists before getting/deleting it, added export command
This commit is contained in:
@ -4,7 +4,7 @@ use chacha20poly1305::{aead::Aead, AeadCore, ChaCha20Poly1305, KeyInit};
|
||||
use futures::{Stream, TryStreamExt};
|
||||
use pbkdf2::pbkdf2_hmac_array;
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
use sea_orm::{prelude::*, ActiveValue::Set, QuerySelect};
|
||||
use sea_orm::{prelude::*, ActiveValue::Set, QueryOrder, QuerySelect};
|
||||
use sha2::Sha256;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
@ -88,18 +88,45 @@ impl Model {
|
||||
}
|
||||
|
||||
impl Entity {
|
||||
/// Gets a list of account names of a user
|
||||
pub async fn get_names(
|
||||
pub async fn get_all(
|
||||
user_id: u64,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<impl Stream<Item = crate::Result<String>> + '_> {
|
||||
) -> crate::Result<impl Stream<Item = crate::Result<Model>> + '_> {
|
||||
let result = Self::find()
|
||||
.select_only()
|
||||
.column(Column::Name)
|
||||
.filter(Column::UserId.eq(user_id))
|
||||
.into_tuple()
|
||||
.stream(db)
|
||||
.await?;
|
||||
Ok(result.map_err(Into::into))
|
||||
}
|
||||
|
||||
/// Gets a list of account names of a user
|
||||
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()
|
||||
.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.map_err(Into::into))
|
||||
}
|
||||
|
||||
pub async fn exists(
|
||||
user_id: u64,
|
||||
account_name: impl Into<String>,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<bool> {
|
||||
let result = Self::find_by_id((user_id, account_name.into()))
|
||||
.select_only()
|
||||
.column(Column::UserId)
|
||||
.into_tuple::<u64>()
|
||||
.one(db)
|
||||
.await?;
|
||||
Ok(result.is_some())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user