mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-04 10:11:21 +00:00
4b4b99aa78
* Allow community mods to see votes in addition to admins * Use Post instead of PostView --------- Co-authored-by: SleeplessOne1917 <insomnia-void@protonmail.com>
30 lines
906 B
Rust
30 lines
906 B
Rust
use actix_web::web::{Data, Json, Query};
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
post::{ListPostLikes, ListPostLikesResponse},
|
|
utils::is_mod_or_admin,
|
|
};
|
|
use lemmy_db_schema::{source::post::Post, traits::Crud};
|
|
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> {
|
|
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?;
|
|
|
|
let post_likes =
|
|
VoteView::list_for_post(&mut context.pool(), data.post_id, data.page, data.limit).await?;
|
|
|
|
Ok(Json(ListPostLikesResponse { post_likes }))
|
|
}
|