fix: dedicated methods for uris
so i dont always wonder if its plural or not
This commit is contained in:
parent
44478d7d2b
commit
178ad1b75d
4 changed files with 17 additions and 5 deletions
|
@ -5,8 +5,7 @@ use crate::{activitystream::Base, model::activity, server::Context};
|
|||
|
||||
|
||||
pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||
let uri = format!("http://localhost:3000/activities/{id}");
|
||||
match activity::Entity::find_by_id(uri).one(ctx.db()).await {
|
||||
match activity::Entity::find_by_id(ctx.activity_uri(id)).one(ctx.db()).await {
|
||||
Ok(Some(activity)) => Ok(Json(activity.underlying_json_object())),
|
||||
Ok(None) => Err(StatusCode::NOT_FOUND),
|
||||
Err(e) => {
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{activitystream::Base, model::object, server::Context};
|
|||
|
||||
|
||||
pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||
match object::Entity::find_by_id(ctx.uri("objects", id)).one(ctx.db()).await {
|
||||
match object::Entity::find_by_id(ctx.object_uri(id)).one(ctx.db()).await {
|
||||
Ok(Some(object)) => Ok(Json(object.underlying_json_object())),
|
||||
Ok(None) => Err(StatusCode::NOT_FOUND),
|
||||
Err(e) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ pub async fn list(State(_db) : State<Arc<DatabaseConnection>>) -> Result<Json<se
|
|||
}
|
||||
|
||||
pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||
match user::Entity::find_by_id(ctx.uri("users", id)).one(ctx.db()).await {
|
||||
match user::Entity::find_by_id(ctx.user_uri(id)).one(ctx.db()).await {
|
||||
Ok(Some(user)) => Ok(Json(user.underlying_json_object())),
|
||||
Ok(None) => Err(StatusCode::NOT_FOUND),
|
||||
Err(e) => {
|
||||
|
@ -29,7 +29,7 @@ pub async fn outbox(
|
|||
|
||||
// find requested recent post, to filter based on its date (use now() as fallback)
|
||||
let before = if let Some(before) = page.max_id {
|
||||
match model::activity::Entity::find_by_id(ctx.uri("activities", before))
|
||||
match model::activity::Entity::find_by_id(ctx.activity_uri(before))
|
||||
.one(ctx.db()).await
|
||||
{
|
||||
Ok(None) => return Err(StatusCode::NOT_FOUND),
|
||||
|
|
|
@ -10,6 +10,7 @@ struct ContextInner {
|
|||
db: DatabaseConnection,
|
||||
domain: String,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new(db: DatabaseConnection, mut domain: String) -> Self {
|
||||
if !domain.starts_with("http") {
|
||||
|
@ -31,6 +32,18 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn user_uri(&self, id: String) -> String {
|
||||
self.uri("users", id)
|
||||
}
|
||||
|
||||
pub fn object_uri(&self, id: String) -> String {
|
||||
self.uri("objects", id)
|
||||
}
|
||||
|
||||
pub fn activity_uri(&self, id: String) -> String {
|
||||
self.uri("activities", id)
|
||||
}
|
||||
|
||||
pub fn id(&self, id: String) -> String {
|
||||
if id.starts_with(&self.0.domain) {
|
||||
let mut out = id.replace(&self.0.domain, "");
|
||||
|
|
Loading…
Reference in a new issue