New perm concept, reference, and adding routes.

This commit is contained in:
Paul Makles
2020-12-29 13:02:04 +00:00
parent 798047625a
commit eb382fa1ec
14 changed files with 196 additions and 46 deletions

View File

@@ -0,0 +1,42 @@
use crate::database::entities::{Channel, User};
use mongodb::bson::{Bson, doc, from_bson};
use crate::util::result::{Error, Result};
use crate::database::get_collection;
use rocket_contrib::json::JsonValue;
use futures::StreamExt;
#[get("/dms")]
pub async fn req(user: User) -> Result<JsonValue> {
let mut cursor = get_collection("channels")
.find(
doc! {
"$or": [
{
"type": "DirectMessage",
"active": true
},
{
"type": "Group"
}
],
"recipients": user.id
},
None
)
.await
.map_err(|_| Error::DatabaseError { operation: "find", with: "channels" })?;
let mut channels: Vec<Channel> = vec![];
while let Some(result) = cursor.next().await {
if let Ok(doc) = result {
channels.push(
from_bson(Bson::Document(doc))
.map_err(|_| Error::DatabaseError { operation: "from_bson", with: "channel" })?
);
}
}
Ok(json!(
channels
))
}