diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index 1750098..fd1e956 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -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; \ No newline at end of file +pub mod res_find_virtual_directory; +pub mod res_create_conversation; \ No newline at end of file diff --git a/src/api_data/res_create_conversation.rs b/src/api_data/res_create_conversation.rs new file mode 100644 index 0000000..3a33445 --- /dev/null +++ b/src/api_data/res_create_conversation.rs @@ -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(), + } + } +} \ No newline at end of file diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index ce095da..62d19a1 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -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)) } \ No newline at end of file