mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2026-02-01 14:25:04 -06:00
feat: add permission/user/group models, start integration into code
This commit is contained in:
@@ -11,3 +11,7 @@ export 'server_stats_api/paperless_server_stats_api.dart';
|
||||
export 'server_stats_api/paperless_server_stats_api_impl.dart';
|
||||
export 'tasks_api/paperless_tasks_api.dart';
|
||||
export 'tasks_api/paperless_tasks_api_impl.dart';
|
||||
export 'user_api/paperless_user_api.dart';
|
||||
export 'user_api/paperless_user_api_v2_impl.dart';
|
||||
export 'user_api/paperless_user_api_v3.dart';
|
||||
export 'user_api/paperless_user_api_v3_impl.dart';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
abstract class PaperlessUserApi {
|
||||
Future<int> findCurrentUserId();
|
||||
Future<UserModel> find(int id);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/modules/user_api/paperless_user_api.dart';
|
||||
|
||||
class PaperlessUserApiV2Impl implements PaperlessUserApi {
|
||||
final Dio client;
|
||||
|
||||
PaperlessUserApiV2Impl(this.client);
|
||||
|
||||
@override
|
||||
Future<int> findCurrentUserId() async {
|
||||
final response = await client.get("/api/ui_settings/");
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['user']['id'];
|
||||
}
|
||||
throw const PaperlessServerException.unknown();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserModel> find(int id) async {
|
||||
final response = await client.get("/api/ui_settings/");
|
||||
if (response.statusCode == 200) {
|
||||
return UserModelV2.fromJson(response.data);
|
||||
}
|
||||
throw const PaperlessServerException.unknown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:paperless_api/src/models/user_model.dart';
|
||||
|
||||
abstract class PaperlessUserApiV3 {
|
||||
Future<Iterable<UserModel>> findWhere({
|
||||
String startsWith,
|
||||
String endsWith,
|
||||
String contains,
|
||||
String username,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/modules/user_api/paperless_user_api.dart';
|
||||
import 'package:paperless_api/src/modules/user_api/paperless_user_api_v3.dart';
|
||||
|
||||
class PaperlessUserApiV3Impl implements PaperlessUserApi, PaperlessUserApiV3 {
|
||||
final Dio dio;
|
||||
|
||||
PaperlessUserApiV3Impl(this.dio);
|
||||
|
||||
@override
|
||||
Future<UserModel> find(int id) async {
|
||||
final response = await dio.get("/api/users/$id/");
|
||||
if (response.statusCode == 200) {
|
||||
return UserModelV3.fromJson(response.data);
|
||||
}
|
||||
throw const PaperlessServerException.unknown();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Iterable<UserModel>> findWhere({
|
||||
String startsWith = '',
|
||||
String endsWith = '',
|
||||
String contains = '',
|
||||
String username = '',
|
||||
}) async {
|
||||
final response = await dio.get("/api/users/", queryParameters: {
|
||||
"username__istartswith": startsWith,
|
||||
"username__iendswith": endsWith,
|
||||
"username__icontains": contains,
|
||||
"username__iexact": username,
|
||||
});
|
||||
if (response.statusCode == 200) {
|
||||
return PagedSearchResult<UserModel>.fromJson(
|
||||
response.data,
|
||||
UserModelV3.fromJson as UserModel Function(Object?),
|
||||
).results;
|
||||
}
|
||||
throw const PaperlessServerException.unknown();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> findCurrentUserId() async {
|
||||
final response = await dio.get("/api/ui_settings/");
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['user_id'];
|
||||
}
|
||||
throw const PaperlessServerException.unknown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user