mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can send friendship request
This commit is contained in:
parent
91d12bb061
commit
baf568142d
@ -61,3 +61,28 @@ pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
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)),
|
||||
|
||||
|
@ -61,7 +61,16 @@ fn get_list(friend_query: &GetFriendsQuery) -> ResultBoxError<Vec<Friend>> {
|
||||
query.exec(db_to_friend)
|
||||
}
|
||||
|
||||
/// Check out wheterher a user has sent a request to another user
|
||||
/// Send a new friendship request
|
||||
pub fn send_request(user_id: &UserID, target_user: &UserID) -> ResultBoxError {
|
||||
database::InsertQuery::new(FRIENDS_TABLE)
|
||||
.add_user_id("ID_personne", target_user)
|
||||
.add_user_id("ID_amis", user_id)
|
||||
.add_legacy_bool("actif", false)
|
||||
.insert_drop_result()
|
||||
}
|
||||
|
||||
/// 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)
|
||||
.cond_user_id("ID_personne", target_user)
|
||||
|
Loading…
Reference in New Issue
Block a user