1
0
Fork 0
forked from alemi/upub
upub/src/model/mod.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

pub mod object;
pub mod activity;
pub mod user;
pub mod config;
2024-03-22 02:29:37 +01:00
pub mod relation;
pub mod addressing;
pub mod share;
pub mod like;
pub mod credential;
pub mod session;
pub mod delivery;
2024-03-25 21:18:12 +01:00
pub mod application;
2024-03-22 02:29:37 +01:00
2024-04-06 18:03:13 +02:00
#[cfg(feature = "faker")]
2024-03-21 20:36:28 +01:00
pub mod faker;
2024-03-16 20:09:06 +01:00
#[derive(Debug, Clone, thiserror::Error)]
#[error("missing required field: '{0}'")]
2024-03-19 01:00:44 +01:00
pub struct FieldError(pub &'static str);
2024-03-16 20:09:06 +01:00
impl From<FieldError> for axum::http::StatusCode {
fn from(value: FieldError) -> Self {
tracing::error!("bad request: {value}");
axum::http::StatusCode::BAD_REQUEST
}
}
2024-03-21 20:36:46 +01:00
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, sea_orm::FromJsonQueryResult)]
pub struct Audience(pub Vec<String>);
2024-04-12 21:55:19 +02:00
impl<T: apb::Base> From<apb::Node<T>> for Audience {
fn from(value: apb::Node<T>) -> Self {
2024-03-21 20:36:46 +01:00
Audience(
match value {
apb::Node::Empty => vec![],
apb::Node::Link(l) => vec![l.href().to_string()],
apb::Node::Object(o) => if let Some(id) = o.id() { vec![id.to_string()] } else { vec![] },
2024-04-12 21:55:19 +02:00
apb::Node::Array(arr) => arr.into_iter().filter_map(|l| Some(l.id()?.to_string())).collect(),
2024-03-21 20:36:46 +01:00
}
)
2024-03-20 07:53:45 +01:00
}
}
2024-03-21 20:36:46 +01:00