diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index b0999c2..0653c79 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -16,4 +16,5 @@ pub mod res_find_user_by_virtual_directory; pub mod res_find_virtual_directory; pub mod res_create_conversation; pub mod conversation_api; -mod legacy_api_bool; \ No newline at end of file +mod legacy_api_bool; +pub mod res_find_private_conversations; \ No newline at end of file diff --git a/src/api_data/res_find_private_conversations.rs b/src/api_data/res_find_private_conversations.rs new file mode 100644 index 0000000..a17a1d3 --- /dev/null +++ b/src/api_data/res_find_private_conversations.rs @@ -0,0 +1,20 @@ +//! Find private conversations result +//! +//! @author Pierre Hubert + +use serde::Serialize; + +#[derive(Serialize)] +#[allow(non_snake_case)] +pub struct ResFindPrivateConversations { + conversationsID: Vec +} + +impl ResFindPrivateConversations { + /// Construct a new instance of this structure + pub fn new(list: Vec) -> ResFindPrivateConversations { + ResFindPrivateConversations { + conversationsID: list + } + } +} \ No newline at end of file diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index d33f52b..bc7d15b 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -4,6 +4,7 @@ use crate::api_data::conversation_api::ConversationAPI; use crate::api_data::res_create_conversation::ResCreateConversation; +use crate::api_data::res_find_private_conversations::ResFindPrivateConversations; use crate::controllers::routes::RequestResult; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::new_conversation::NewConversation; @@ -136,7 +137,11 @@ pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult { // Query the database let list = conversations_helper::find_private(r.user_id()?, other_user)?; - println!("{:#?}", list); + if list.is_empty() { + if !allow_create { + return r.not_found(format!("Not any private conversation was found. The server was not allowed to create a new one...")); + } + } - r.success("implement it") + r.set_response(ResFindPrivateConversations::new(list)) } \ No newline at end of file