mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-28 14:38:52 +00:00
Can remove a friendship
This commit is contained in:
parent
e59541720d
commit
f540716b86
@ -117,3 +117,14 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
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!")
|
||||
}
|
@ -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)),
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user