diff --git a/src/db/application.rs b/src/db/application.rs new file mode 100644 index 0000000..150c5fc --- /dev/null +++ b/src/db/application.rs @@ -0,0 +1,39 @@ +use chrono::{DateTime, FixedOffset, Local}; +use serde::{Deserialize, Serialize}; + +use super::DbResult; +use crate::query_call_consume; +use crate::CallDB; + +#[derive(Serialize, Deserialize, Default)] +pub struct Application +where + C: Serialize, +{ + pub _id: bson::oid::ObjectId, + pub created_at: DateTime, + #[serde(flatten)] + pub from: C, +} + +impl Application +where + C: Serialize + for<'a> Deserialize<'a> + Send + Sync, +{ + pub fn new(from: C) -> Self { + Self { + _id: Default::default(), + created_at: Local::now().into(), + from, + } + } + + query_call_consume!(store, self, db, Self, { + let db = db.get_database().await; + let ci = db.collection::("applications"); + + ci.insert_one(&self).await?; + + Ok(self) + }); +} diff --git a/src/db/mod.rs b/src/db/mod.rs index f4fa1b9..076b7be 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1,3 +1,4 @@ +pub mod application; pub mod callback_info; use std::time::Duration;