create Application

This commit is contained in:
Akulij 2025-05-02 17:07:35 +03:00
parent fdfc8a8270
commit 5bc6a8343d
2 changed files with 40 additions and 0 deletions

39
src/db/application.rs Normal file
View File

@ -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<C>
where
C: Serialize,
{
pub _id: bson::oid::ObjectId,
pub created_at: DateTime<FixedOffset>,
#[serde(flatten)]
pub from: C,
}
impl<C> Application<C>
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::<Self>("applications");
ci.insert_one(&self).await?;
Ok(self)
});
}

View File

@ -1,3 +1,4 @@
pub mod application;
pub mod callback_info;
use std::time::Duration;