2023-05-25 12:55:20 +00:00
|
|
|
pub mod antenna;
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use schemars::JsonSchema;
|
|
|
|
|
|
|
|
use crate::error::Error;
|
|
|
|
|
|
|
|
#[async_trait]
|
2023-05-27 09:50:07 +00:00
|
|
|
pub trait Repository<T: JsonSchema> {
|
2023-05-25 12:55:20 +00:00
|
|
|
async fn pack(self) -> Result<T, Error>;
|
2023-06-02 08:34:49 +00:00
|
|
|
async fn pack_by_id(id: String) -> Result<T, Error>;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod macros {
|
|
|
|
macro_rules! impl_pack_by_id {
|
|
|
|
($a:ty, $b:ident) => {
|
|
|
|
match <$a>::find_by_id($b).one(database::get_database()?).await? {
|
|
|
|
None => Err(Error::NotFound),
|
|
|
|
Some(m) => m.pack().await,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) use impl_pack_by_id;
|
2023-05-25 12:55:20 +00:00
|
|
|
}
|