1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-28 14:38:52 +00:00

Finish to implement conversation creation

This commit is contained in:
Pierre HUBERT 2020-06-04 17:47:52 +02:00
parent 435ba32653
commit 55566a85dc
3 changed files with 28 additions and 7 deletions

View File

@ -13,4 +13,5 @@ pub mod current_user_id;
pub mod user_info;
pub mod custom_emoji;
pub mod res_find_user_by_virtual_directory;
pub mod res_find_virtual_directory;
pub mod res_find_virtual_directory;
pub mod res_create_conversation;

View File

@ -0,0 +1,22 @@
//! # Create conversation result
//!
//! @author Pierre Hubert
use serde::{Serialize};
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct ResCreateConversation {
conversationID: u64,
success: String,
}
impl ResCreateConversation {
/// Construct a new Result instance
pub fn new(conv_id: u64) -> ResCreateConversation {
ResCreateConversation {
conversationID: conv_id,
success: "The conversation was successfully created!".to_string(),
}
}
}

View File

@ -6,6 +6,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
use crate::controllers::routes::RequestResult;
use crate::helpers::{user_helper, conversations_helper};
use crate::data::new_conversation::NewConversation;
use crate::api_data::res_create_conversation::ResCreateConversation;
/// Create a new conversation
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
@ -36,13 +37,10 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
name,
owner_following: r.post_bool("follow")?,
members,
can_everyone_add_members: r.post_bool_opt("canEveryoneAddMembers", true)
can_everyone_add_members: r.post_bool_opt("canEveryoneAddMembers", true),
};
// TODO : adapt for API
println!("Conversation to create: {:#?}", conv);
// Create the conversation
let conv_id = conversations_helper::create(&conv)?;
println!("conv: {}", conv_id);
r.success("create")
r.set_response(ResCreateConversation::new(conv_id))
}