TF-4171 Add datasource/repository/interactor for get all labels

This commit is contained in:
dab246
2025-11-25 00:11:16 +07:00
committed by Dat H. Pham
parent 4af0ee1086
commit f4302e06e8
15 changed files with 250 additions and 0 deletions
@@ -0,0 +1,6 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/model/label.dart';
abstract class LabelDatasource {
Future<List<Label>> getAllLabels(AccountId accountId);
}
@@ -0,0 +1,22 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/labels/data/datasource/label_datasource.dart';
import 'package:tmail_ui_user/features/labels/data/network/label_api.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class LabelDatasourceImpl extends LabelDatasource {
final LabelApi _labelApi;
final ExceptionThrower _exceptionThrower;
LabelDatasourceImpl(this._labelApi, this._exceptionThrower);
@override
Future<List<Label>> getAllLabels(AccountId accountId) {
return Future.sync(() async {
return await _labelApi.getAllLabels(accountId);
}).catchError((error, stackTrace) async {
await _exceptionThrower.throwException(error, stackTrace);
throw error;
});
}
}
@@ -0,0 +1,26 @@
import 'package:jmap_dart_client/http/http_client.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/jmap_request.dart';
import 'package:labels/labels.dart';
class LabelApi {
final HttpClient _httpClient;
LabelApi(this._httpClient);
Future<List<Label>> getAllLabels(AccountId accountId) async {
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
final method = GetLabelMethod(accountId);
final invocation = builder.invocation(method);
final result =
await (builder..usings(method.requiredCapabilities)).build().execute();
final response = result.parse<GetLabelResponse>(
invocation.methodCallId,
GetLabelResponse.deserialize,
);
return response?.list ?? [];
}
}
@@ -0,0 +1,15 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/labels/data/datasource/label_datasource.dart';
import 'package:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
class LabelRepositoryImpl extends LabelRepository {
final LabelDatasource _labelDatasource;
LabelRepositoryImpl(this._labelDatasource);
@override
Future<List<Label>> getAllLabels(AccountId accountId) {
return _labelDatasource.getAllLabels(accountId);
}
}