mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 08:55:16 +00:00
Count the number of likes of a user
This commit is contained in:
35
src/helpers/likes_helper.rs
Normal file
35
src/helpers/likes_helper.rs
Normal file
@ -0,0 +1,35 @@
|
||||
//! # Likes helper
|
||||
//!
|
||||
//! Module dedicated to likes management
|
||||
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::helpers::database::QueryInfo;
|
||||
use crate::constants::database_tables_names::LIKES_TABLE;
|
||||
|
||||
pub enum LikeType {
|
||||
USER,
|
||||
POST,
|
||||
COMMENT,
|
||||
GROUP
|
||||
}
|
||||
|
||||
impl LikeType {
|
||||
|
||||
/// Get matching database type
|
||||
pub fn to_db_type(&self) -> String {
|
||||
match self {
|
||||
LikeType::USER => "page".to_string(),
|
||||
LikeType::POST => "texte".to_string(),
|
||||
LikeType::COMMENT => "commentaire".to_string(),
|
||||
LikeType::GROUP => "group".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Count the number of likes over an element
|
||||
pub fn count(id: u64, kind: LikeType) -> ResultBoxError<usize> {
|
||||
QueryInfo::new(LIKES_TABLE)
|
||||
.cond_u64("ID_type", id)
|
||||
.cond("type", kind.to_db_type().as_ref())
|
||||
.exec_count()
|
||||
}
|
@ -5,4 +5,5 @@ pub mod account_helper;
|
||||
pub mod user_helper;
|
||||
pub mod friends_helper;
|
||||
pub mod custom_emojies_helper;
|
||||
pub mod background_image_helper;
|
||||
pub mod background_image_helper;
|
||||
pub mod likes_helper;
|
Reference in New Issue
Block a user