diff --git a/src/api_data/post_api.rs b/src/api_data/post_api.rs index 9e24173..37b5dd2 100644 --- a/src/api_data/post_api.rs +++ b/src/api_data/post_api.rs @@ -8,7 +8,8 @@ use crate::api_data::survey_api::SurveyAPI; use crate::data::error::ResultBoxError; use crate::data::post::{Post, PostKind}; use crate::data::user::UserID; -use crate::helpers::{movies_helper, survey_helper}; +use crate::helpers::{likes_helper, movies_helper, survey_helper}; +use crate::helpers::likes_helper::LikeType; use crate::utils::user_data_utils::user_data_url; #[derive(Serialize)] @@ -44,6 +45,10 @@ pub struct PostAPI { // Survey specific data_survey: Option, + + // Likes information + likes: u64, + userlike: bool, } impl PostAPI { @@ -80,6 +85,13 @@ impl PostAPI { // Survey specific data_survey: None, + + // Likes information + likes: likes_helper::count(p.id, LikeType::POST)? as u64, + userlike: user + .as_ref() + .map(|user_id| likes_helper::is_liking(user_id, p.id, LikeType::POST)) + .unwrap_or(Ok(false))?, }; match &p.kind {