mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Complete information
This commit is contained in:
		@@ -4,9 +4,10 @@
 | 
			
		||||
 | 
			
		||||
use crate::constants::database_tables_names::POSTS_TABLE;
 | 
			
		||||
use crate::data::error::ResultBoxError;
 | 
			
		||||
use crate::data::post::{Post, PostVisibilityLevel};
 | 
			
		||||
use crate::data::post::{Post, PostPageKind, PostVisibilityLevel};
 | 
			
		||||
use crate::data::user::UserID;
 | 
			
		||||
use crate::helpers::{database, friends_helper};
 | 
			
		||||
use crate::utils::date_utils::time;
 | 
			
		||||
 | 
			
		||||
impl PostVisibilityLevel {
 | 
			
		||||
    pub fn to_db(&self) -> u32 {
 | 
			
		||||
@@ -17,6 +18,16 @@ impl PostVisibilityLevel {
 | 
			
		||||
            PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS => 50,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn from_db(val: u32) -> PostVisibilityLevel {
 | 
			
		||||
        match val {
 | 
			
		||||
            1 => PostVisibilityLevel::VISIBILITY_PUBLIC,
 | 
			
		||||
            2 => PostVisibilityLevel::VISIBILITY_FRIENDS,
 | 
			
		||||
            3 => PostVisibilityLevel::VISIBILITY_USER,
 | 
			
		||||
            50 => PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS,
 | 
			
		||||
            _ => PostVisibilityLevel::VISIBILITY_PUBLIC,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -112,7 +123,25 @@ fn get_user(query: &PostsQuery, target_id: &UserID) -> ResultBoxError<Vec<Post>>
 | 
			
		||||
 | 
			
		||||
/// Turn a post into a database entry
 | 
			
		||||
fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
 | 
			
		||||
    let user_id = if res.get_u64("ID_amis")? == 0 {
 | 
			
		||||
        res.get_user_id("ID_personne")
 | 
			
		||||
    } else {
 | 
			
		||||
        res.get_user_id("ID_amis")
 | 
			
		||||
    }?;
 | 
			
		||||
 | 
			
		||||
    let target_page = if res.get_u64("group_id")? == 0 {
 | 
			
		||||
        PostPageKind::PAGE_KIND_USER(res.get_user_id("ID_personne")?)
 | 
			
		||||
    } else {
 | 
			
		||||
        PostPageKind::PAGE_KIND_GROUP(res.get_group_id("group_id")?)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    Ok(Post {
 | 
			
		||||
        id: res.get_u64("ID")?
 | 
			
		||||
        // General information
 | 
			
		||||
        id: res.get_u64("ID")?,
 | 
			
		||||
        user_id: user_id.clone(),
 | 
			
		||||
        time_create: res.get_u64("time_insert").unwrap_or(time()),
 | 
			
		||||
        target_page,
 | 
			
		||||
        content: res.get_optional_str("texte")?,
 | 
			
		||||
        visibility: PostVisibilityLevel::from_db(res.get_u32("niveau_visibilite")?),
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user