mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-17 12:48:04 +00:00
Improve code
This commit is contained in:
src
@ -91,7 +91,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
};
|
||||
|
||||
// Start to create post
|
||||
let post = Post {
|
||||
let mut post = Post {
|
||||
id: 0,
|
||||
user_id: r.user_id()?,
|
||||
time_create: time(),
|
||||
@ -102,19 +102,22 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
};
|
||||
|
||||
// Handle different post types
|
||||
match r.post_string("kind")?.as_str() {
|
||||
post.kind = 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())?;
|
||||
}
|
||||
|
||||
PostKind::POST_KIND_TEXT
|
||||
}
|
||||
|
||||
_ => {
|
||||
return r.internal_error(ExecError::boxed_new("Unsupported kind of post!"));
|
||||
r.internal_error(ExecError::boxed_new("Unsupported kind of post!"))?;
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create the post
|
||||
let post_id = posts_helper::create(&post)?;
|
||||
|
Reference in New Issue
Block a user