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

Can remove a friendship request

This commit is contained in:
Pierre HUBERT 2020-06-30 10:24:18 +02:00
parent baf568142d
commit 13f86fd8c1
4 changed files with 36 additions and 0 deletions

View File

@ -86,3 +86,18 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
r.success("The friendship request was successfully sent!")
}
/// Cancel a friendship request
pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?;
if !friends_helper::sent_request(&r.user_id()?, &friend_id)? {
r.forbidden("No friendship request was sent to this user!".to_string())?;
}
friends_helper::remove_request(&r.user_id()?, &friend_id)?;
// TODO : delete related notifications
r.success("Friendship request removed!")
}

View File

@ -99,6 +99,9 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/friends/sendRequest", Box::new(friends_controller::send_request)),
Route::post("/friends/removeRequest", Box::new(friends_controller::cancel_request)),
// Conversations controller
Route::post("/conversations/create", Box::new(conversations_controller::create)),

View File

@ -611,6 +611,15 @@ impl DeleteQuery {
self
}
pub fn cond_legacy_bool(mut self, key: &str, value: bool) -> DeleteQuery {
let value = match value {
true => 1,
false => 0
};
self.conditions.insert(key.to_string(), Value::from(value));
self
}
pub fn cond_user_id(mut self, key: &str, value: &UserID) -> DeleteQuery {
self.conditions.insert(key.to_string(), Value::from(value.id()));
self

View File

@ -70,6 +70,15 @@ pub fn send_request(user_id: &UserID, target_user: &UserID) -> ResultBoxError {
.insert_drop_result()
}
/// Remove a friendship request
pub fn remove_request(user_id: &UserID, target_user: &UserID) -> ResultBoxError {
database::DeleteQuery::new(FRIENDS_TABLE)
.cond_user_id("ID_personne", target_user)
.cond_user_id("ID_amis", user_id)
.cond_legacy_bool("actif", false)
.exec()
}
/// Check out whether a user has sent a request to another user
pub fn sent_request(user_id: &UserID, target_user: &UserID) -> ResultBoxError<bool> {
database::QueryInfo::new(FRIENDS_TABLE)