1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00
comunicmobile/lib/helpers/virtual_directory_helper.dart

51 lines
1.3 KiB
Dart
Raw Normal View History

2020-04-16 10:06:01 +00:00
import 'package:comunic/models/api_request.dart';
/// Virtual directory helper
///
/// @author Pierre Hubert
enum VirtualDirectoryType { USER, GROUP, NONE }
class VirtualDirectoryResult {
final VirtualDirectoryType type;
final int? id;
2020-04-16 10:06:01 +00:00
const VirtualDirectoryResult({
required this.type,
2020-04-16 10:06:01 +00:00
this.id,
2022-03-11 15:27:01 +00:00
});
2020-04-16 10:06:01 +00:00
}
class VirtualDirectoryHelper {
/// Find a virtual directory
Future<VirtualDirectoryResult> find(String directory) async {
final response = await APIRequest(
uri: "virtualDirectory/find",
needLogin: true,
args: {"directory": directory}).exec();
switch (response.code) {
case 404:
return VirtualDirectoryResult(type: VirtualDirectoryType.NONE);
case 200:
2022-03-10 19:36:55 +00:00
final id = response.getObject()["id"];
final kind = response.getObject()["kind"];
2020-04-16 10:06:01 +00:00
switch (kind) {
case "user":
return VirtualDirectoryResult(
type: VirtualDirectoryType.USER, id: id);
case "group":
return VirtualDirectoryResult(
type: VirtualDirectoryType.GROUP, id: id);
default:
throw Exception("Unsupported virtual directory kind: $kind");
}
default:
throw new Exception("Could not get virtual directory!");
}
}
}