1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 22:18:51 +00:00

Load like information

This commit is contained in:
Pierre HUBERT 2020-07-04 17:14:49 +02:00
parent 532bd9e48d
commit cab3954edc

View File

@ -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<SurveyAPI>,
// 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 {