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

Can create text posts

This commit is contained in:
2020-07-07 19:14:16 +02:00
parent 6b9c9079c8
commit c82e9d6e69
6 changed files with 143 additions and 5 deletions

View File

@ -3,11 +3,15 @@
//! @author Pierre Hubert
use crate::api_data::post_api::PostAPI;
use crate::api_data::res_create_post::ResCreatePost;
use crate::controllers::routes::RequestResult;
use crate::data::error::ExecError;
use crate::data::group::GroupAccessLevel;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::data::post::{PostAccessLevel, PostPageKind};
use crate::data::post::{Post, PostAccessLevel, PostKind, PostPageKind, PostVisibilityLevel};
use crate::helpers::{groups_helper, posts_helper, user_helper};
use crate::utils::date_utils::time;
use crate::utils::string_utils::check_string_before_insert;
/// Get the list of posts of a user
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
@ -86,7 +90,35 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
}
};
println!("Create post on {:?}", target_page);
// Start to create post
let post = Post {
id: 0,
user_id: r.user_id()?,
time_create: time(),
target_page,
content: Some(r.post_string_opt("content", 0, false)?),
visibility: PostVisibilityLevel::VISIBILITY_PUBLIC,
kind: PostKind::POST_KIND_TEXT,
};
r.success("Continue implementation")
// Handle different post types
match r.post_string("kind")?.as_str() {
// Text posts
"text" => {
if !check_string_before_insert(post.content.as_ref().unwrap_or(&String::new())) {
r.forbidden("Specified post content is invalid!".to_string())?;
}
}
_ => {
return r.internal_error(ExecError::boxed_new("Unsupported kind of post!"));
}
}
// Create the post
let post_id = posts_helper::create(&post)?;
// TODO : create a notification
r.set_response(ResCreatePost::new(post_id))
}