mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
Add more guild routes.
This commit is contained in:
@@ -1,38 +1,24 @@
|
||||
use rocket::http::{ RawStr };
|
||||
use rocket::request::{ FromParam };
|
||||
use bson::{ bson, doc, from_bson };
|
||||
use bson::{bson, doc, from_bson};
|
||||
use rocket::http::RawStr;
|
||||
use rocket::request::FromParam;
|
||||
|
||||
use crate::database;
|
||||
|
||||
use database::channel::Channel;
|
||||
use database::message::Message;
|
||||
use database::guild::Guild;
|
||||
|
||||
impl<'r> FromParam<'r> for Channel {
|
||||
impl<'r> FromParam<'r> for Guild {
|
||||
type Error = &'r RawStr;
|
||||
|
||||
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
|
||||
let col = database::get_db().collection("channels");
|
||||
let result = col.find_one(doc! { "_id": param.to_string() }, None).unwrap();
|
||||
let col = database::get_db().collection("guilds");
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> FromParam<'r> for Message {
|
||||
type Error = &'r RawStr;
|
||||
|
||||
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
|
||||
let col = database::get_db().collection("messages");
|
||||
let result = col.find_one(doc! { "_id": param.to_string() }, None).unwrap();
|
||||
|
||||
if let Some(message) = result {
|
||||
Ok(from_bson(bson::Bson::Document(message)).expect("Failed to unwrap message."))
|
||||
} else {
|
||||
Err(param)
|
||||
}
|
||||
if let Some(guild) = result {
|
||||
Ok(from_bson(bson::Bson::Document(guild)).expect("Failed to unwrap guild."))
|
||||
} else {
|
||||
Err(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod auth;
|
||||
pub mod channel;
|
||||
pub mod guild;
|
||||
|
||||
Reference in New Issue
Block a user