mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-29 06:58:50 +00:00
Can get a conversation ID from a POST request
This commit is contained in:
parent
bfd7cc0630
commit
619fc171e1
@ -55,5 +55,7 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
/// Get information about a single conversation
|
/// Get information about a single conversation
|
||||||
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
|
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
r.success("Implement id")
|
let conversation_id = r.post_conv_id("conversationID")?;
|
||||||
|
|
||||||
|
r.success("do it")
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ use crate::data::api_client::APIClient;
|
|||||||
use crate::data::config::conf;
|
use crate::data::config::conf;
|
||||||
use crate::data::error::{ExecError, ResultBoxError};
|
use crate::data::error::{ExecError, ResultBoxError};
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::{account_helper, api_helper, user_helper};
|
use crate::helpers::{account_helper, api_helper, user_helper, conversations_helper};
|
||||||
use crate::utils::virtual_directories_utils::check_virtual_directory;
|
use crate::utils::virtual_directories_utils::check_virtual_directory;
|
||||||
|
|
||||||
/// Http request handler
|
/// Http request handler
|
||||||
@ -264,6 +264,10 @@ impl HttpRequestHandler {
|
|||||||
Ok(self.post_string(name)?.parse::<i64>()?)
|
Ok(self.post_string(name)?.parse::<i64>()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn post_u64(&mut self, name: &str) -> ResultBoxError<u64> {
|
||||||
|
Ok(self.post_string(name)?.parse::<u64>()?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get a boolean included in a POST request
|
/// Get a boolean included in a POST request
|
||||||
pub fn post_bool(&mut self, name: &str) -> ResultBoxError<bool> {
|
pub fn post_bool(&mut self, name: &str) -> ResultBoxError<bool> {
|
||||||
Ok(self.post_string(name)?.eq("true"))
|
Ok(self.post_string(name)?.eq("true"))
|
||||||
@ -343,4 +347,15 @@ impl HttpRequestHandler {
|
|||||||
|
|
||||||
Ok(dir)
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get & return the ID of the conversation included in the POST request
|
||||||
|
pub fn post_conv_id(&mut self, name: &str) -> ResultBoxError<u64> {
|
||||||
|
let conv_id = self.post_u64(name)?;
|
||||||
|
|
||||||
|
if !conversations_helper::does_user_belongs_to(self.user_id()?, conv_id)? {
|
||||||
|
self.forbidden(format!("You do not belong to conversation {} !", conv_id))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(conv_id)
|
||||||
|
}
|
||||||
}
|
}
|
@ -77,7 +77,15 @@ pub fn get_list_members(conv_id: u64) -> ResultBoxError<Vec<UserID>> {
|
|||||||
database::QueryInfo::new(CONV_USERS_TABLE)
|
database::QueryInfo::new(CONV_USERS_TABLE)
|
||||||
.cond_u64("conv_id", conv_id)
|
.cond_u64("conv_id", conv_id)
|
||||||
.add_field("user_id")
|
.add_field("user_id")
|
||||||
.exec(|res|res.get_user_id("user_id"))
|
.exec(|res| res.get_user_id("user_id"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a user belongs to a conversation or not
|
||||||
|
pub fn does_user_belongs_to(user_id: UserID, conv_id: u64) -> ResultBoxError<bool> {
|
||||||
|
Ok(database::QueryInfo::new(CONV_USERS_TABLE)
|
||||||
|
.cond_u64("conv_id", conv_id)
|
||||||
|
.cond_user_id("user_id", user_id)
|
||||||
|
.exec_count()? > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn a database entry into a ConversationInfo object
|
/// Turn a database entry into a ConversationInfo object
|
||||||
|
Loading…
Reference in New Issue
Block a user