2024-01-03 18:39:21 +00:00
|
|
|
use actix_web::web::{Data, Json, Query};
|
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
|
|
|
post::{ListPostLikes, ListPostLikesResponse},
|
2024-01-23 23:47:28 +00:00
|
|
|
utils::is_mod_or_admin,
|
2024-01-03 18:39:21 +00:00
|
|
|
};
|
2024-01-23 23:47:28 +00:00
|
|
|
use lemmy_db_schema::{source::post::Post, traits::Crud};
|
2024-01-03 18:39:21 +00:00
|
|
|
use lemmy_db_views::structs::{LocalUserView, VoteView};
|
|
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
|
|
|
|
/// Lists likes for a post
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn list_post_likes(
|
|
|
|
data: Query<ListPostLikes>,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
local_user_view: LocalUserView,
|
|
|
|
) -> Result<Json<ListPostLikesResponse>, LemmyError> {
|
2024-01-23 23:47:28 +00:00
|
|
|
let post = Post::read(&mut context.pool(), data.post_id).await?;
|
|
|
|
is_mod_or_admin(
|
|
|
|
&mut context.pool(),
|
|
|
|
&local_user_view.person,
|
|
|
|
post.community_id,
|
|
|
|
)
|
|
|
|
.await?;
|
2024-01-03 18:39:21 +00:00
|
|
|
|
|
|
|
let post_likes =
|
|
|
|
VoteView::list_for_post(&mut context.pool(), data.post_id, data.page, data.limit).await?;
|
|
|
|
|
|
|
|
Ok(Json(ListPostLikesResponse { post_likes }))
|
|
|
|
}
|