mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-27 22:18:51 +00:00
Can remove a friendship request
This commit is contained in:
parent
baf568142d
commit
13f86fd8c1
@ -85,4 +85,19 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
// TODO : create a notification
|
||||
|
||||
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!")
|
||||
}
|
@ -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)),
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user