1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-20 14:15:22 +00:00

Can send friendship request

This commit is contained in:
2020-06-30 10:06:53 +02:00
parent 91d12bb061
commit baf568142d
3 changed files with 37 additions and 1 deletions

@@ -60,4 +60,29 @@ pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
let status = friends_helper::get_status(&curr_user_id, &friend_id)?;
r.set_response(FriendshipStatusAPI::new(&status))
}
/// Send a new friendship request
pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?;
if friend_id == r.user_id()? {
r.forbidden("You can not sent friendship request to yourself!".to_string())?;
}
let status = friends_helper::get_status(&r.user_id()?, &friend_id)?;
if status.are_friend {
r.forbidden("You are already a friend of this person!".to_string())?;
}
if status.sent_request || status.received_request {
r.forbidden("A friendship request is already in progress!".to_string())?;
}
friends_helper::send_request(&r.user_id()?, &friend_id)?;
// TODO : create a notification
r.success("The friendship request was successfully sent!")
}

@@ -97,6 +97,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/friends/getStatus", Box::new(friends_controller::get_status)),
Route::post("/friends/sendRequest", Box::new(friends_controller::send_request)),
// Conversations controller
Route::post("/conversations/create", Box::new(conversations_controller::create)),