Run rust fmt.

This commit is contained in:
Paul Makles
2020-04-06 13:07:05 +01:00
parent 8e908ce105
commit ec1e91aee1
16 changed files with 1094 additions and 1025 deletions

View File

@@ -1,8 +1,8 @@
use crate::database::{ self, user::User };
use crate::database::{self, user::User};
use bson::{ bson, doc };
use rocket_contrib::json::{ JsonValue, Json };
use serde::{ Serialize, Deserialize };
use bson::{bson, doc};
use rocket_contrib::json::{Json, JsonValue};
use serde::{Deserialize, Serialize};
use ulid::Ulid;
use super::channel::ChannelType;
@@ -25,16 +25,22 @@ pub fn create_guild(user: User, info: Json<CreateGuild>) -> JsonValue {
}
let name: String = info.name.chars().take(32).collect();
let description: String = info.description.clone().unwrap_or("No description.".to_string()).chars().take(255).collect();
let description: String = info
.description
.clone()
.unwrap_or("No description.".to_string())
.chars()
.take(255)
.collect();
let nonce: String = info.nonce.chars().take(32).collect();
let channels = database::get_collection("channels");
let col = database::get_collection("guilds");
if let Some(_) = col.find_one(doc! { "nonce": nonce.clone() }, None).unwrap() {
return json!({
"success": false,
"error": "Guild already created!"
})
let channels = database::get_collection("channels");
let col = database::get_collection("guilds");
if let Some(_) = col.find_one(doc! { "nonce": nonce.clone() }, None).unwrap() {
return json!({
"success": false,
"error": "Guild already created!"
});
}
let channel_id = Ulid::new().to_string();
@@ -44,37 +50,43 @@ pub fn create_guild(user: User, info: Json<CreateGuild>) -> JsonValue {
"channel_type": ChannelType::GUILDCHANNEL as u32,
"name": "general",
},
None) {
None,
) {
return json!({
"success": false,
"error": "Failed to create guild channel."
})
});
}
let id = Ulid::new().to_string();
if col.insert_one(
doc! {
"_id": id.clone(),
"nonce": nonce,
"name": name,
"description": description,
"owner": user.id.clone(),
"channels": [
channel_id.clone()
],
"members": [
user.id
],
"invites": [],
},
None
).is_ok() {
let id = Ulid::new().to_string();
if col
.insert_one(
doc! {
"_id": id.clone(),
"nonce": nonce,
"name": name,
"description": description,
"owner": user.id.clone(),
"channels": [
channel_id.clone()
],
"members": [
user.id
],
"invites": [],
},
None,
)
.is_ok()
{
json!({
"success": true,
"id": id,
})
} else {
channels.delete_one(doc! { "_id": channel_id }, None).expect("Failed to delete the channel we just made.");
channels
.delete_one(doc! { "_id": channel_id }, None)
.expect("Failed to delete the channel we just made.");
json!({
"success": false,