Add an endpoint to like posts
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
use rocket::response::Redirect;
|
||||
|
||||
use activity_pub::activity::Like;
|
||||
use activity_pub::outbox::broadcast;
|
||||
use db_conn::DbConn;
|
||||
use models::likes;
|
||||
use models::posts::Post;
|
||||
use models::users::User;
|
||||
|
||||
#[get("/~/<blog>/<slug>/like")]
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
|
||||
likes::Like::insert(&*conn, likes::NewLike {
|
||||
post_id: post.id,
|
||||
user_id: user.id
|
||||
});
|
||||
let act = Like::new(&user, &post, &*conn);
|
||||
broadcast(&*conn, &user, act, user.get_followers(&*conn));
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod blogs;
|
||||
pub mod comments;
|
||||
pub mod instance;
|
||||
pub mod likes;
|
||||
pub mod posts;
|
||||
pub mod session;
|
||||
pub mod user;
|
||||
|
||||
+2
-1
@@ -31,7 +31,8 @@ fn details(blog: String, slug: String, conn: DbConn) -> Template {
|
||||
"content": c.content,
|
||||
"author": c.get_author(&*conn)
|
||||
})
|
||||
}).collect::<Vec<serde_json::Value>>()
|
||||
}).collect::<Vec<serde_json::Value>>(),
|
||||
"n_likes": post.get_likes(&*conn).len()
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user