1
0
Fork 0
forked from alemi/upub
upub/src/activitypub/activity.rs

23 lines
717 B
Rust
Raw Normal View History

use axum::{extract::{Path, State}, http::StatusCode};
2024-03-20 08:56:35 +01:00
use sea_orm::EntityTrait;
2024-03-21 01:42:29 +01:00
use crate::{activitystream::{prelude::*, Node}, model::{activity, object}, server::Context};
use super::JsonLD;
pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result<JsonLD<serde_json::Value>, StatusCode> {
2024-03-21 01:42:29 +01:00
match activity::Entity::find_by_id(ctx.aid(id))
.find_also_related(object::Entity)
.one(ctx.db())
.await
{
Ok(Some((activity, object))) => Ok(JsonLD(activity.underlying_json_object().set_object(Node::maybe_object(object)))),
Ok(None) => Err(StatusCode::NOT_FOUND),
Err(e) => {
tracing::error!("error querying for activity: {e}");
Err(StatusCode::INTERNAL_SERVER_ERROR)
},
}
}