mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Create user access denied route
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:comunic/helpers/database/friends_database_helper.dart';
|
||||
import 'package:comunic/lists/friends_list.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/friend.dart';
|
||||
import 'package:comunic/models/friend_status.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Friends helper
|
||||
@ -65,7 +66,7 @@ class FriendsHelper {
|
||||
"accept": accept.toString()
|
||||
}).exec();
|
||||
|
||||
return response.code == 200;
|
||||
return response.isOK;
|
||||
}
|
||||
|
||||
/// Update following status for a friend
|
||||
@ -91,6 +92,28 @@ class FriendsHelper {
|
||||
return response.code == 200;
|
||||
}
|
||||
|
||||
/// Get friendship status. Throw an exception in case of failure
|
||||
Future<FriendStatus> getFriendshipStatus(int userID) async {
|
||||
final response = await APIRequest(
|
||||
uri: "friends/getStatus",
|
||||
needLogin: true,
|
||||
args: {"friendID": userID.toString()},
|
||||
).exec();
|
||||
|
||||
if (response.code != 200)
|
||||
throw Exception("Could not get friendship status!");
|
||||
|
||||
final obj = response.getObject();
|
||||
|
||||
return FriendStatus(
|
||||
userID: userID,
|
||||
areFriend: obj["are_friend"],
|
||||
sentRequest: obj["sent_request"],
|
||||
receivedRequest: obj["received_request"],
|
||||
following: obj["following"],
|
||||
);
|
||||
}
|
||||
|
||||
/// Get and return the list of friends of an other user
|
||||
///
|
||||
/// Throws an Exception if could not get the list of friends
|
||||
@ -106,4 +129,24 @@ class FriendsHelper {
|
||||
|
||||
return Set<int>.from(response.getArray());
|
||||
}
|
||||
|
||||
/// Send a friendship request to a specified user
|
||||
Future<bool> sendRequest(int userID) async {
|
||||
return (await APIRequest(
|
||||
uri: "friends/sendRequest",
|
||||
needLogin: true,
|
||||
args: {"friendID": userID.toString()},
|
||||
).exec())
|
||||
.isOK;
|
||||
}
|
||||
|
||||
/// Cancel a friendship request
|
||||
Future<bool> cancelRequest(int userID) async {
|
||||
return (await APIRequest(
|
||||
uri: "friends/removeRequest",
|
||||
needLogin: true,
|
||||
args: {"friendID": userID.toString()},
|
||||
).exec())
|
||||
.isOK;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,11 @@ import 'package:comunic/models/user.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
/// Handle advanced information error
|
||||
enum GetUserAdvancedInformationErrorCause { NOT_FOUND, NETWORK_ERROR }
|
||||
enum GetUserAdvancedInformationErrorCause {
|
||||
NOT_FOUND,
|
||||
NETWORK_ERROR,
|
||||
NOT_AUTHORIZED
|
||||
}
|
||||
|
||||
class GetUserAdvancedUserError extends Error {
|
||||
final GetUserAdvancedInformationErrorCause cause;
|
||||
@ -76,6 +80,11 @@ class UsersHelper {
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Get information about a single user. Throws in case of failure
|
||||
Future<User> getSingleWithThrow(int user) async {
|
||||
return (await getListWithThrow(Set<int>()..add(user)))[0];
|
||||
}
|
||||
|
||||
/// Get users information from a given [Set]
|
||||
Future<UsersList> getList(Set<int> users,
|
||||
{bool forceDownload = false}) async {
|
||||
@ -125,6 +134,9 @@ class UsersHelper {
|
||||
if (response.code == 404)
|
||||
cause = GetUserAdvancedInformationErrorCause.NOT_FOUND;
|
||||
|
||||
if (response.code == 401)
|
||||
cause = GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED;
|
||||
|
||||
throw new GetUserAdvancedUserError(cause);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user