TF-2035 Implement parse calendar event method
(cherry picked from commit c8681dcde084e82453b5ea2770db37f2222d675c)
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/data/network/calendar_event_api.dart';
|
||||||
|
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||||
|
|
||||||
|
class CalendarEventDataSourceImpl extends CalendarEventDataSource {
|
||||||
|
|
||||||
|
final CalendarEventAPI _calendarEventAPI;
|
||||||
|
final ExceptionThrower _exceptionThrower;
|
||||||
|
|
||||||
|
CalendarEventDataSourceImpl(this._calendarEventAPI, this._exceptionThrower);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await _calendarEventAPI.parse(accountId, blobIds);
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:jmap_dart_client/http/http_client.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/calendar/parse/calendar_event_parse_method.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/calendar/parse/calendar_event_parse_response.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart';
|
||||||
|
|
||||||
|
class CalendarEventAPI {
|
||||||
|
|
||||||
|
final HttpClient _httpClient;
|
||||||
|
|
||||||
|
CalendarEventAPI(this._httpClient);
|
||||||
|
|
||||||
|
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) async {
|
||||||
|
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||||
|
final calendarEventParseMethod = CalendarEventParseMethod(accountId, blobIds);
|
||||||
|
final calendarEventParseInvocation = requestBuilder.invocation(calendarEventParseMethod);
|
||||||
|
final response = await (requestBuilder
|
||||||
|
..usings(calendarEventParseMethod.requiredCapabilities))
|
||||||
|
.build()
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final calendarEventParseResponse = response.parse<CalendarEventParseResponse>(
|
||||||
|
calendarEventParseInvocation.methodCallId,
|
||||||
|
CalendarEventParseResponse.deserialize);
|
||||||
|
|
||||||
|
if (calendarEventParseResponse?.parsed?.isNotEmpty == true) {
|
||||||
|
return calendarEventParseResponse!.parsed!.values.toList();
|
||||||
|
} else if (calendarEventParseResponse?.notParsable?.isNotEmpty == true) {
|
||||||
|
throw NotParsableCalendarEventException();
|
||||||
|
} else if (calendarEventParseResponse?.notFound?.isNotEmpty == true) {
|
||||||
|
throw NotFoundCalendarEventException();
|
||||||
|
} else {
|
||||||
|
throw NotParsableCalendarEventException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/domain/repository/calendar_event_repository.dart';
|
||||||
|
|
||||||
|
class CalendarEventRepositoryImpl extends CalendarEventRepository {
|
||||||
|
|
||||||
|
final CalendarEventDataSource _calendarEventDataSource;
|
||||||
|
|
||||||
|
CalendarEventRepositoryImpl(this._calendarEventDataSource);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) {
|
||||||
|
return _calendarEventDataSource.parse(accountId, blobIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
class NotFoundCalendarEventException implements Exception {}
|
||||||
|
|
||||||
|
class NotParsableCalendarEventException implements Exception {}
|
||||||
Reference in New Issue
Block a user