Run rust fmt.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user