1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 17:05:16 +00:00

Check if a user is liking a page or not

This commit is contained in:
2020-06-01 11:12:05 +02:00
parent cef5838ef4
commit 637408c626
2 changed files with 23 additions and 4 deletions

View File

@ -5,6 +5,7 @@
use crate::data::error::ResultBoxError;
use crate::helpers::database::QueryInfo;
use crate::constants::database_tables_names::LIKES_TABLE;
use crate::data::user::UserID;
pub enum LikeType {
USER,
@ -32,4 +33,17 @@ pub fn count(id: u64, kind: LikeType) -> ResultBoxError<usize> {
.cond_u64("ID_type", id)
.cond("type", kind.to_db_type().as_ref())
.exec_count()
}
/// Check if a user likes an element or not
pub fn is_liking(user_id: UserID, id: u64, kind: LikeType) -> ResultBoxError<bool> {
if user_id == 0 {
return Ok(false);
}
Ok(QueryInfo::new(LIKES_TABLE)
.cond_u64("ID_type", id)
.cond_i64("ID_personne", user_id)
.cond("type", kind.to_db_type().as_ref())
.exec_count()? > 0)
}