iceshrimp-legacy/packages/backend/native-utils/src/model/repository/antenna.rs

57 lines
1.7 KiB
Rust
Raw Normal View History

2023-05-25 14:55:20 +02:00
use async_trait::async_trait;
2023-06-02 12:22:09 +02:00
use cfg_if::cfg_if;
2023-07-10 08:17:06 +02:00
use sea_orm::EntityTrait;
2023-05-25 14:55:20 +02:00
2023-06-02 14:48:12 +02:00
use crate::database;
2023-07-10 08:17:06 +02:00
use crate::model::entity::{antenna, user_group_joining};
2023-06-02 14:48:12 +02:00
use crate::model::error::Error;
use crate::model::schema::Antenna;
2023-05-25 14:55:20 +02:00
2023-06-02 10:34:49 +02:00
use super::macros::impl_pack_by_id;
2023-05-25 14:55:20 +02:00
use super::Repository;
#[async_trait]
impl Repository<Antenna> for antenna::Model {
async fn pack(self) -> Result<Antenna, Error> {
let db = database::get_database()?;
let user_group_joining = match self.user_group_joining_id {
None => None,
Some(id) => user_group_joining::Entity::find_by_id(id).one(db).await?,
};
let user_group_id = match user_group_joining {
None => None,
Some(m) => Some(m.user_group_id),
};
2023-06-02 12:22:09 +02:00
cfg_if! {
if #[cfg(feature = "napi")] {
let created_at: String = self.created_at.to_rfc3339();
} else {
let created_at: chrono::DateTime<chrono::Utc> = self.created_at.into();
}
}
2023-05-25 14:55:20 +02:00
Ok(Antenna {
id: self.id,
2023-06-02 12:22:09 +02:00
created_at,
2023-05-25 14:55:20 +02:00
name: self.name,
2023-06-01 00:12:59 +02:00
keywords: self.keywords.into(),
exclude_keywords: self.exclude_keywords.into(),
2023-05-25 14:55:20 +02:00
src: self.src.try_into()?,
user_list_id: self.user_list_id,
user_group_id,
2023-07-17 00:32:32 +02:00
users: self.users,
2023-06-01 00:12:59 +02:00
instances: self.instances.into(),
2023-05-25 14:55:20 +02:00
case_sensitive: self.case_sensitive,
notify: self.notify,
with_replies: self.with_replies,
with_file: self.with_file,
2023-07-10 08:17:06 +02:00
has_unread_note: false,
2023-05-25 14:55:20 +02:00
})
}
2023-06-02 10:34:49 +02:00
async fn pack_by_id(id: String) -> Result<Antenna, Error> {
impl_pack_by_id!(antenna::Entity, id)
}
2023-05-25 14:55:20 +02:00
}