|
@@ -1,6 +1,7 @@
|
|
|
use serde::{Serialize, Deserialize};
|
|
use serde::{Serialize, Deserialize};
|
|
|
use bson::{oid::ObjectId, DateTime, Bson, doc};
|
|
use bson::{oid::ObjectId, DateTime, Bson, doc};
|
|
|
use mongodb::Collection;
|
|
use mongodb::Collection;
|
|
|
|
|
+use futures::stream::TryStreamExt;
|
|
|
|
|
|
|
|
use crate::app_error::AppError;
|
|
use crate::app_error::AppError;
|
|
|
use crate::dto::account::CreateInput;
|
|
use crate::dto::account::CreateInput;
|
|
@@ -39,6 +40,14 @@ impl Account {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ pub async fn find_by_user(collection: &Collection<Account>, user_id: ObjectId) -> Result<Vec<Account>, AppError> {
|
|
|
|
|
+ Ok(collection
|
|
|
|
|
+ .find(doc!{"_id": user_id}, None)
|
|
|
|
|
+ .await?
|
|
|
|
|
+ .try_collect::<Vec<_>>()
|
|
|
|
|
+ .await?)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pub async fn find_by_id(collection: &Collection<Account>, account_id: ObjectId) -> Result<Account, AppError> {
|
|
pub async fn find_by_id(collection: &Collection<Account>, account_id: ObjectId) -> Result<Account, AppError> {
|
|
|
match collection.find_one(doc!{"_id": account_id}, None).await {
|
|
match collection.find_one(doc!{"_id": account_id}, None).await {
|
|
|
Ok(Some(a)) => Ok(a),
|
|
Ok(Some(a)) => Ok(a),
|