2020-06-30 19:23:52 +02:00
|
|
|
mod mod_item;
|
2020-07-16 10:16:35 -07:00
|
|
|
mod team_item;
|
2020-06-30 19:23:52 +02:00
|
|
|
mod version_item;
|
|
|
|
|
|
|
|
|
|
use crate::database::DatabaseError::NotFound;
|
|
|
|
|
use crate::database::Result;
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use bson::doc;
|
|
|
|
|
use bson::Document;
|
|
|
|
|
pub use mod_item::Mod;
|
|
|
|
|
use mongodb::Database;
|
2020-07-16 10:16:35 -07:00
|
|
|
pub use team_item::Team;
|
|
|
|
|
pub use team_item::TeamMember;
|
|
|
|
|
pub use version_item::FileHash;
|
2020-06-30 19:23:52 +02:00
|
|
|
pub use version_item::Version;
|
2020-07-16 10:16:35 -07:00
|
|
|
pub use version_item::VersionFile;
|
2020-06-30 19:23:52 +02:00
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
pub trait Item {
|
|
|
|
|
fn get_collection() -> &'static str;
|
|
|
|
|
async fn get_by_id(client: Database, id: &str) -> Result<Box<Self>> {
|
|
|
|
|
let filter = doc! { "_id": id };
|
|
|
|
|
let collection = client.collection(Self::get_collection());
|
|
|
|
|
let doc: Document = match collection.find_one(filter, None).await? {
|
|
|
|
|
Some(e) => e,
|
|
|
|
|
None => return Err(NotFound()),
|
|
|
|
|
};
|
|
|
|
|
let elem: Box<Self> = Self::from_doc(doc)?;
|
|
|
|
|
Ok(elem)
|
|
|
|
|
}
|
|
|
|
|
fn from_doc(elem: Document) -> Result<Box<Self>>;
|
|
|
|
|
}
|