1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 22:18:51 +00:00

Can remove a friendship

This commit is contained in:
Pierre HUBERT 2020-06-30 14:27:31 +02:00
parent e59541720d
commit f540716b86
3 changed files with 28 additions and 0 deletions

View File

@ -116,4 +116,15 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
// TODO : create a notification
r.set_response("Response to the friendship request successfully saved!")
}
/// Remove a friend from the list
pub fn remove_friend(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?;
friends_helper::remove_friendship(r.user_id_ref()?, &friend_id)?;
// TODO : Delete any related notification
r.success("The friend was removed from the list!")
}

View File

@ -103,6 +103,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/friends/respondRequest", Box::new(friends_controller::respond_request)),
Route::post("/friends/remove", Box::new(friends_controller::remove_friend)),
// Conversations controller
Route::post("/conversations/create", Box::new(conversations_controller::create)),

View File

@ -119,6 +119,21 @@ pub fn are_friend(user_one: &UserID, user_two: &UserID) -> ResultBoxError<bool>
.cond_i64("actif", 1))? > 0)
}
/// Delete a friendship
pub fn remove_friendship(user_one: &UserID, user_two: &UserID) -> ResultBoxError {
database::DeleteQuery::new(FRIENDS_TABLE)
.cond_user_id("ID_personne", user_one)
.cond_user_id("ID_amis", user_two)
.exec()?;
database::DeleteQuery::new(FRIENDS_TABLE)
.cond_user_id("ID_personne", user_two)
.cond_user_id("ID_amis", user_one)
.exec()?;
Ok(())
}
/// Count the number of friends of a user
pub fn count_friends(user_id: &UserID) -> ResultBoxError<usize> {
QueryInfo::new(FRIENDS_TABLE)