mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-31 07:34:45 +00:00 
			
		
		
		
	Start to delete posts
This commit is contained in:
		| @@ -263,5 +263,9 @@ pub fn update_content(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|  | ||||
| /// Delete a post | ||||
| pub fn delete(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|     r.success("Implement me") | ||||
|     let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; | ||||
|  | ||||
|     posts_helper::delete(&post)?; | ||||
|  | ||||
|     r.success("Post deleted.") | ||||
| } | ||||
| @@ -2,20 +2,20 @@ | ||||
| //! | ||||
| //! Module dedicated to likes management | ||||
|  | ||||
| use crate::data::error::ResultBoxError; | ||||
| use crate::helpers::database::QueryInfo; | ||||
| use crate::constants::database_tables_names::LIKES_TABLE; | ||||
| use crate::data::error::ResultBoxError; | ||||
| use crate::data::user::UserID; | ||||
| use crate::helpers::database; | ||||
| use crate::helpers::database::QueryInfo; | ||||
|  | ||||
| pub enum LikeType { | ||||
|     USER, | ||||
|     POST, | ||||
|     COMMENT, | ||||
|     GROUP | ||||
|     GROUP, | ||||
| } | ||||
|  | ||||
| impl LikeType { | ||||
|  | ||||
|     /// Get matching database type | ||||
|     pub fn to_db_type(&self) -> String { | ||||
|         match self { | ||||
| @@ -46,4 +46,12 @@ pub fn is_liking(user_id: &UserID, id: u64, kind: LikeType) -> ResultBoxError<bo | ||||
|         .cond_user_id("ID_personne", user_id) | ||||
|         .cond("type", kind.to_db_type().as_ref()) | ||||
|         .exec_count()? > 0) | ||||
| } | ||||
|  | ||||
| /// Delete all the likes associated with a post | ||||
| pub fn delete_all(id: u64, kind: LikeType) -> ResultBoxError { | ||||
|     database::DeleteQuery::new(LIKES_TABLE) | ||||
|         .cond_u64("ID_type", id) | ||||
|         .cond_str("type", &kind.to_db_type()) | ||||
|         .exec() | ||||
| } | ||||
| @@ -11,7 +11,8 @@ use crate::data::group_member::GroupMembershipLevel; | ||||
| use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink}; | ||||
| use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_MOVIE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE}; | ||||
| use crate::data::user::UserID; | ||||
| use crate::helpers::{database, friends_helper, groups_helper, user_helper}; | ||||
| use crate::helpers::{database, friends_helper, groups_helper, likes_helper, user_helper}; | ||||
| use crate::helpers::likes_helper::LikeType; | ||||
| use crate::utils::date_utils::{mysql_date, time}; | ||||
|  | ||||
| impl PostVisibilityLevel { | ||||
| @@ -399,6 +400,16 @@ pub fn set_content(post_id: u64, new_content: &str) -> ResultBoxError { | ||||
|         .exec() | ||||
| } | ||||
|  | ||||
| /// Delete a post | ||||
| pub fn delete(p: &Post) -> ResultBoxError { | ||||
|     // TODO : delete all the notifications related with the post | ||||
|  | ||||
|     // Delete all the likes associated with the post | ||||
|     likes_helper::delete_all(p.id, LikeType::POST)?; | ||||
|  | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| /// 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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user