Add / remove from group + clean up code.

This commit is contained in:
Paul Makles
2020-04-10 13:09:04 +01:00
parent 83f1fbe747
commit a910bd657a
8 changed files with 173 additions and 95 deletions

View File

@@ -5,7 +5,6 @@ use rocket::request::FromParam;
use serde::{Deserialize, Serialize};
use crate::database;
use crate::database::guild::Guild;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GuildRef {
@@ -74,20 +73,3 @@ impl<'r> FromParam<'r> for GuildRef {
}
}
}
impl<'r> FromParam<'r> for Guild {
type Error = &'r RawStr;
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
let col = database::get_collection("guilds");
let result = col
.find_one(doc! { "_id": param.to_string() }, None)
.unwrap();
if let Some(guild) = result {
Ok(from_bson(bson::Bson::Document(guild)).expect("Failed to unwrap guild."))
} else {
Err(param)
}
}
}