2020-07-11 06:14:30 +00:00
|
|
|
//! # API Notification object
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
2020-07-13 09:17:35 +00:00
|
|
|
use serde::Serialize;
|
2020-07-11 06:14:30 +00:00
|
|
|
|
2020-07-13 09:17:35 +00:00
|
|
|
use crate::api_data::type_container_api::TypeContainerAPI;
|
2020-07-11 06:14:30 +00:00
|
|
|
use crate::data::notification::Notification;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct NotificationAPI {
|
|
|
|
id: u64,
|
|
|
|
time_create: u64,
|
|
|
|
seen: bool,
|
|
|
|
from_user_id: u64,
|
|
|
|
dest_user_id: u64,
|
|
|
|
on_elem_id: u64,
|
|
|
|
on_elem_type: String,
|
|
|
|
#[serde(flatten)]
|
2020-07-13 09:17:35 +00:00
|
|
|
type_container: TypeContainerAPI,
|
2020-07-11 06:14:30 +00:00
|
|
|
event_visibility: String,
|
|
|
|
from_container_id: Option<u64>,
|
|
|
|
from_container_type: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NotificationAPI {
|
|
|
|
pub fn new(n: &Notification) -> NotificationAPI {
|
|
|
|
NotificationAPI {
|
|
|
|
id: n.id,
|
|
|
|
time_create: n.time_create,
|
|
|
|
seen: n.seen,
|
|
|
|
from_user_id: n.from_user_id.id(),
|
|
|
|
dest_user_id: n.dest_user_id.id(),
|
|
|
|
on_elem_id: n.on_elem_id,
|
|
|
|
on_elem_type: n.on_elem_type.to_api(),
|
2020-07-13 09:17:35 +00:00
|
|
|
type_container: TypeContainerAPI::new(n.kind.to_api()),
|
2020-07-11 06:14:30 +00:00
|
|
|
event_visibility: n.visibility.to_api(),
|
|
|
|
from_container_id: n.container_id,
|
|
|
|
from_container_type: n.container_type.as_ref().map(|f| f.to_api()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn for_list(l: &Vec<Notification>) -> Vec<NotificationAPI> {
|
|
|
|
l.iter().map(Self::new).collect()
|
|
|
|
}
|
|
|
|
}
|