mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 10:08:02 -06:00
added initial draft of inbox
This commit is contained in:
@@ -4,12 +4,14 @@ class ErrorMessage implements Exception {
|
||||
final StackTrace? stackTrace;
|
||||
final int? httpStatusCode;
|
||||
|
||||
const ErrorMessage(this.code,
|
||||
{this.details, this.stackTrace, this.httpStatusCode});
|
||||
const ErrorMessage(
|
||||
this.code, {
|
||||
this.details,
|
||||
this.stackTrace,
|
||||
this.httpStatusCode,
|
||||
});
|
||||
|
||||
factory ErrorMessage.unknown() {
|
||||
return const ErrorMessage(ErrorCode.unknown);
|
||||
}
|
||||
const ErrorMessage.unknown() : this(ErrorCode.unknown);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
15
lib/core/model/paperless_statistics.dart
Normal file
15
lib/core/model/paperless_statistics.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:paperless_mobile/core/type/types.dart';
|
||||
|
||||
class PaperlessStatistics {
|
||||
final int documentsTotal;
|
||||
final int documentsInInbox;
|
||||
|
||||
PaperlessStatistics({
|
||||
required this.documentsTotal,
|
||||
required this.documentsInInbox,
|
||||
});
|
||||
|
||||
PaperlessStatistics.fromJson(JSON json)
|
||||
: documentsTotal = json['documents_total'],
|
||||
documentsInInbox = json['documents_inbox'];
|
||||
}
|
||||
29
lib/core/service/paperless_statistics_service.dart
Normal file
29
lib/core/service/paperless_statistics_service.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:paperless_mobile/core/model/paperless_statistics.dart';
|
||||
import 'package:paperless_mobile/core/type/types.dart';
|
||||
|
||||
abstract class PaperlessStatisticsService {
|
||||
Future<PaperlessStatistics> getStatistics();
|
||||
}
|
||||
|
||||
@Injectable(as: PaperlessStatisticsService)
|
||||
class PaperlessStatisticsServiceImpl extends PaperlessStatisticsService {
|
||||
final BaseClient client;
|
||||
|
||||
PaperlessStatisticsServiceImpl(@Named('timeoutClient') this.client);
|
||||
|
||||
@override
|
||||
Future<PaperlessStatistics> getStatistics() async {
|
||||
final response = await client.get(Uri.parse('/api/statistics/'));
|
||||
if (response.statusCode == 200) {
|
||||
return PaperlessStatistics.fromJson(
|
||||
jsonDecode(utf8.decode(response.bodyBytes)) as JSON,
|
||||
);
|
||||
}
|
||||
throw const ErrorMessage.unknown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user