forked from jmug/stoatchat
Run cargo fmt.
This commit is contained in:
@@ -25,13 +25,16 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
"active": false
|
||||
}
|
||||
},
|
||||
None
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "channel" })?;
|
||||
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "channel",
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
_ => unimplemented!()
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use validator::Validate;
|
||||
use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use rocket::request::Form;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use mongodb::{bson::{doc, from_document}, options::FindOptions};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize, FromForm)]
|
||||
pub struct Options {
|
||||
@@ -20,7 +23,8 @@ pub struct Options {
|
||||
|
||||
#[get("/<target>/messages?<options..>")]
|
||||
pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<JsonValue> {
|
||||
options.validate()
|
||||
options
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
@@ -51,14 +55,19 @@ pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<Json
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "find", with: "messages" })?;
|
||||
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "messages",
|
||||
})?;
|
||||
|
||||
let mut messages = vec![];
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
messages.push(
|
||||
from_document::<Message>(doc)
|
||||
.map_err(|_| Error::DatabaseError { operation: "from_document", with: "message" })?
|
||||
from_document::<Message>(doc).map_err(|_| Error::DatabaseError {
|
||||
operation: "from_document",
|
||||
with: "message",
|
||||
})?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::Json;
|
||||
use validator::Validate;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
@@ -18,7 +18,8 @@ pub struct Data {
|
||||
|
||||
#[post("/<target>/messages", data = "<message>")]
|
||||
pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<()> {
|
||||
message.validate()
|
||||
message
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
@@ -33,11 +34,15 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<()> {
|
||||
doc! {
|
||||
"nonce": &message.nonce
|
||||
},
|
||||
None
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "find_one", with: "message" })?
|
||||
.is_some() {
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find_one",
|
||||
with: "message",
|
||||
})?
|
||||
.is_some()
|
||||
{
|
||||
Err(Error::AlreadySentMessage)?
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use rocket::Route;
|
||||
|
||||
mod fetch_channel;
|
||||
mod delete_channel;
|
||||
mod message_send;
|
||||
mod fetch_channel;
|
||||
mod message_fetch;
|
||||
mod message_send;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
|
||||
Reference in New Issue
Block a user