chore: polish

This commit is contained in:
əlemi 2024-03-20 07:55:03 +01:00
parent 1cede82df6
commit c51ca0744b
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 57 additions and 2 deletions

View file

@ -19,3 +19,4 @@ thiserror = "1.0.58"
tokio = { version = "1.35.1", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
uuid = { version = "1.8.0", features = ["v4"] }

View file

@ -10,8 +10,13 @@ use sea_orm::{DatabaseConnection, EntityTrait, IntoActiveModel};
use crate::{activitystream::{object::{ObjectType, activity::{Activity, ActivityType}}, Base, BaseType, Node}, model};
pub fn uri_id(id: String) -> String {
if id.starts_with("http") { id } else { format!("http://localhost:3000/users/{id}") }
pub fn uri_id(entity: &str, id: String) -> String {
if id.starts_with("http") { id } else { format!("http://localhost:3000/{entity}/{id}") }
}
pub fn id_uri(id: &str) -> &str {
id.split('/').last().unwrap_or("")
}
}
pub async fn inbox(State(db) : State<Arc<DatabaseConnection>>, Json(object): Json<serde_json::Value>) -> Result<Json<serde_json::Value>, StatusCode> {

View file

@ -124,6 +124,18 @@ macro_rules! getter {
}
};
($name:ident -> u64) => {
fn $name(&self) -> Option<u64> {
self.get(stringify!($name))?.as_u64()
}
};
($name:ident::$rename:ident -> u64) => {
fn $name(&self) -> Option<u64> {
self.get(stringify!($rename))?.as_u64()
}
};
($name:ident -> chrono::DateTime<chrono::Utc>) => {
fn $name(&self) -> Option<chrono::DateTime<chrono::Utc>> {
Some(
@ -184,6 +196,39 @@ macro_rules! setter {
}
};
($name:ident::$rename:ident -> &str) => {
paste::item! {
fn [< set_$name >](&mut self, val: Option<&str>) -> &mut Self {
$crate::activitystream::macros::set_maybe_value(
self, stringify!($rename), val.map(|x| serde_json::Value::String(x.to_string()))
);
self
}
}
};
($name:ident -> u64) => {
paste::item! {
fn [< set_$name >](&mut self, val: Option<u64>) -> &mut Self {
$crate::activitystream::macros::set_maybe_value(
self, stringify!($name), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x)))
);
self
}
}
};
($name:ident::$rename:ident -> u64) => {
paste::item! {
fn [< set_$name >](&mut self, val: Option<u64>) -> &mut Self {
$crate::activitystream::macros::set_maybe_value(
self, stringify!($rename), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x)))
);
self
}
}
};
($name:ident -> chrono::DateTime<chrono::Utc>) => {
paste::item! {
fn [< set_$name >](&mut self, val: Option<chrono::DateTime<chrono::Utc>>) -> &mut Self {

View file

@ -29,6 +29,10 @@ pub trait Base {
fn underlying_json_object(self) -> serde_json::Value;
}
pub fn object() -> serde_json::Value {
serde_json::Value::Object(serde_json::Map::default())
}
pub trait BaseMut {
fn set_id(&mut self, val: Option<&str>) -> &mut Self;
fn set_base_type(&mut self, val: Option<BaseType>) -> &mut Self;