making it AP complaint
Some checks failed
CI / Check / Test (push) Has been cancelled

This commit is contained in:
2026-06-30 02:25:42 +02:00
parent 943a0abe54
commit 5ae38c834a
66 changed files with 3635 additions and 2369 deletions

View File

@@ -1,14 +1,60 @@
use std::sync::Arc;
use async_trait::async_trait;
use domain::{models::RemoteGoalEntry, ports::RemoteGoalRepository};
use k_ap::ApObjectHandler;
use chrono::DateTime;
use domain::{
models::RemoteGoalEntry,
ports::{LocalApContentQuery, RemoteGoalRepository},
value_objects::UserId,
};
use k_ap::{ApContentReader, ApObjectHandler};
use url::Url;
use crate::objects::GoalObject;
use crate::objects::{GoalObject, goal_to_ap_object};
use crate::urls::{actor_url, goal_url};
pub struct GoalObjectHandler {
pub remote_goal_repo: Arc<dyn RemoteGoalRepository>,
pub content_query: Arc<dyn LocalApContentQuery>,
pub base_url: String,
}
#[async_trait]
impl ApContentReader for GoalObjectHandler {
async fn get_local_objects_page(
&self,
user_id: uuid::Uuid,
_before: Option<DateTime<chrono::Utc>>,
_limit: usize,
) -> anyhow::Result<Vec<(Url, serde_json::Value, DateTime<chrono::Utc>)>> {
let uid = UserId::from_uuid(user_id);
let goals = self
.content_query
.list_goals_for_user(&uid)
.await
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
let actor = actor_url(&self.base_url, user_id);
let mut results = Vec::new();
for goal in goals {
let ap_id = goal_url(&self.base_url, user_id, goal.year());
let published = DateTime::from_naive_utc_and_offset(*goal.created_at(), chrono::Utc);
let obj = goal_to_ap_object(
ap_id.clone(),
actor.clone(),
goal.year(),
goal.target_count(),
0,
&self.base_url,
);
results.push((ap_id, serde_json::to_value(obj)?, published));
}
Ok(results)
}
async fn count_local_posts(&self) -> anyhow::Result<u64> {
Ok(0)
}
}
#[async_trait]