forked from jmug/stoatchat
Add / remove from group + clean up code.
This commit is contained in:
@@ -160,20 +160,3 @@ impl<'r> FromParam<'r> for UserRef {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> FromParam<'r> for User {
|
||||
type Error = &'r RawStr;
|
||||
|
||||
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
|
||||
let col = database::get_collection("users");
|
||||
let result = col
|
||||
.find_one(doc! { "_id": param.to_string() }, None)
|
||||
.unwrap();
|
||||
|
||||
if let Some(user) = result {
|
||||
Ok(from_bson(bson::Bson::Document(user)).expect("Failed to unwrap user."))
|
||||
} else {
|
||||
Err(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,8 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::database;
|
||||
|
||||
use database::channel::Channel;
|
||||
use database::message::Message;
|
||||
|
||||
impl<'r> FromParam<'r> for Channel {
|
||||
type Error = &'r RawStr;
|
||||
|
||||
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
|
||||
let col = database::get_collection("channels");
|
||||
let result = col
|
||||
.find_one(doc! { "_id": param.to_string() }, None)
|
||||
.unwrap();
|
||||
|
||||
if let Some(channel) = result {
|
||||
Ok(from_bson(bson::Bson::Document(channel)).expect("Failed to unwrap channel."))
|
||||
} else {
|
||||
Err(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct ChannelRef {
|
||||
#[serde(rename = "_id")]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user