simplify: dedupe boilerplate and remove dead code across all layers
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -38,9 +37,6 @@ class AutocompleteApi {
|
||||
technicalDetails: 'core/autocomplete/get: ${response.body}',
|
||||
);
|
||||
}
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return AutocompleteResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
return AutocompleteResponse.fromJson(NextcloudOcs.decode(response.body));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../model/account_data.dart';
|
||||
import '../../model/endpoint_data.dart';
|
||||
|
||||
@@ -6,6 +8,11 @@ import '../../model/endpoint_data.dart';
|
||||
class NextcloudOcs {
|
||||
NextcloudOcs._();
|
||||
|
||||
/// Decodes an OCS v2 JSON envelope and returns its `ocs` object (the wrapper
|
||||
/// every response nests its `meta`/`data` under).
|
||||
static Map<String, dynamic> decode(String raw) =>
|
||||
(jsonDecode(raw) as Map<String, dynamic>)['ocs'] as Map<String, dynamic>;
|
||||
|
||||
static Map<String, String> headers() => {
|
||||
'Accept': 'application/json',
|
||||
'OCS-APIRequest': 'true',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -28,9 +27,7 @@ class SearchFiles {
|
||||
'Files search failed with ${response.statusCode}: ${response.body}',
|
||||
);
|
||||
}
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final ocs = decoded['ocs'] as Map<String, dynamic>;
|
||||
final data = ocs['data'] as Map<String, dynamic>;
|
||||
final data = NextcloudOcs.decode(response.body)['data'] as Map<String, dynamic>;
|
||||
return SearchFilesResponse.fromJson(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'get_chat_params.dart';
|
||||
import 'get_chat_response.dart';
|
||||
@@ -15,10 +14,8 @@ class GetChat extends TalkApi<GetChatResponse> {
|
||||
: super('v1/chat/$chatToken', null, getParameters: params.toJson());
|
||||
|
||||
@override
|
||||
GetChatResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetChatResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
}
|
||||
GetChatResponse assemble(String raw) =>
|
||||
GetChatResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<Response> request(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -57,8 +56,7 @@ class LongPollChat {
|
||||
final status = response.statusCode;
|
||||
if (status == 304) return null;
|
||||
if (status >= 200 && status < 300) {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return GetChatResponse.fromJson(decoded['ocs'] as Map<String, dynamic>)
|
||||
return GetChatResponse.fromJson(NextcloudOcs.decode(response.body))
|
||||
..headers = response.headers;
|
||||
}
|
||||
throw ServerException(
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../api_params.dart';
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../get_poll/get_poll_state_response.dart';
|
||||
import '../talk_api.dart';
|
||||
|
||||
@@ -12,12 +11,8 @@ class ClosePoll extends TalkApi<GetPollStateResponse> {
|
||||
: super('v1/poll/$token/$pollId', null);
|
||||
|
||||
@override
|
||||
GetPollStateResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetPollStateResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
GetPollStateResponse assemble(String raw) =>
|
||||
GetPollStateResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<http.Response> request(
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'create_room_params.dart';
|
||||
import 'create_room_response.dart';
|
||||
@@ -13,10 +12,8 @@ class CreateRoom extends TalkApi<CreateRoomResponse> {
|
||||
CreateRoom(this.params) : super('v4/room', params);
|
||||
|
||||
@override
|
||||
CreateRoomResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return CreateRoomResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
}
|
||||
CreateRoomResponse assemble(String raw) =>
|
||||
CreateRoomResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<Response>? request(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'get_participants_response.dart';
|
||||
|
||||
@@ -10,12 +9,8 @@ class GetParticipants extends TalkApi<GetParticipantsResponse> {
|
||||
GetParticipants(this.token) : super('v4/room/$token/participants', null);
|
||||
|
||||
@override
|
||||
GetParticipantsResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetParticipantsResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
GetParticipantsResponse assemble(String raw) =>
|
||||
GetParticipantsResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<http.Response> request(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'get_poll_state_response.dart';
|
||||
|
||||
@@ -12,12 +11,8 @@ class GetPollState extends TalkApi<GetPollStateResponse> {
|
||||
: super('v1/poll/$token/$pollId', null);
|
||||
|
||||
@override
|
||||
GetPollStateResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetPollStateResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
GetPollStateResponse assemble(String raw) =>
|
||||
GetPollStateResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<http.Response> request(
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../api_params.dart';
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'get_reactions_response.dart';
|
||||
|
||||
@@ -14,12 +13,8 @@ class GetReactions extends TalkApi<GetReactionsResponse> {
|
||||
: super('v1/reaction/$chatToken/$messageId', null);
|
||||
|
||||
@override
|
||||
GetReactionsResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetReactionsResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
GetReactionsResponse assemble(String raw) =>
|
||||
GetReactionsResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<Response>? request(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'get_room_params.dart';
|
||||
import 'get_room_response.dart';
|
||||
@@ -11,10 +10,8 @@ class GetRoom extends TalkApi<GetRoomResponse> {
|
||||
GetRoom(this.params) : super('v4/room', null, getParameters: params.toJson());
|
||||
|
||||
@override
|
||||
GetRoomResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetRoomResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
}
|
||||
GetRoomResponse assemble(String raw) =>
|
||||
GetRoomResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<http.Response> request(
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../api_params.dart';
|
||||
import '../../nextcloud_ocs.dart';
|
||||
import '../get_poll/get_poll_state_response.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'vote_poll_params.dart';
|
||||
@@ -22,12 +23,8 @@ class VotePoll extends TalkApi<GetPollStateResponse> {
|
||||
);
|
||||
|
||||
@override
|
||||
GetPollStateResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetPollStateResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
GetPollStateResponse assemble(String raw) =>
|
||||
GetPollStateResponse.fromJson(NextcloudOcs.decode(raw));
|
||||
|
||||
@override
|
||||
Future<http.Response>? request(
|
||||
|
||||
@@ -10,11 +10,25 @@ import 'auth/auth_interceptor.dart';
|
||||
class MarianumConnectApi {
|
||||
static const Duration _connectTimeout = Duration(seconds: 10);
|
||||
static const Duration _receiveTimeout = Duration(seconds: 20);
|
||||
static const Duration _plainReceiveTimeout = Duration(seconds: 15);
|
||||
|
||||
static final Dio _instance = _build();
|
||||
|
||||
static Dio dio() => _instance;
|
||||
|
||||
/// A fresh dio with the standard JSON options but no interceptors — used by
|
||||
/// the auth queries (login/verify) that must bypass the bearer/demo
|
||||
/// interceptors to avoid a re-auth loop.
|
||||
static Dio plainDio() => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: _connectTimeout,
|
||||
sendTimeout: _connectTimeout,
|
||||
receiveTimeout: _plainReceiveTimeout,
|
||||
responseType: ResponseType.json,
|
||||
contentType: 'application/json',
|
||||
),
|
||||
);
|
||||
|
||||
static Dio _build() {
|
||||
final dio = Dio(
|
||||
BaseOptions(
|
||||
|
||||
@@ -26,4 +26,36 @@ abstract class MarianumConnectQuery {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// GETs [path] and parses the JSON object body with [fromJson].
|
||||
Future<T> getObject<T>(
|
||||
String path,
|
||||
T Function(Map<String, dynamic> json) fromJson, {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint(path),
|
||||
queryParameters: queryParameters,
|
||||
);
|
||||
return fromJson(response.data!);
|
||||
});
|
||||
|
||||
/// GETs [path] and maps each element of the JSON array body with [fromJson].
|
||||
Future<List<T>> getList<T>(
|
||||
String path,
|
||||
T Function(Map<String, dynamic> json) fromJson, {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint(path),
|
||||
queryParameters: queryParameters,
|
||||
);
|
||||
return response.data!
|
||||
.map((e) => fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
});
|
||||
|
||||
/// Formats [d] as an ISO `yyyy-MM-dd` day for MarianumConnect query params.
|
||||
String isoDate(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../auth/token_storage.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
import 'auth_login_response.dart';
|
||||
|
||||
@@ -9,9 +10,6 @@ import 'auth_login_response.dart';
|
||||
/// run through the shared dio instance — that one has the interceptor, which
|
||||
/// would attempt to re-auth us into a loop if our credentials are wrong.
|
||||
class AuthLogin extends MarianumConnectQuery {
|
||||
static const Duration _connectTimeout = Duration(seconds: 10);
|
||||
static const Duration _receiveTimeout = Duration(seconds: 15);
|
||||
|
||||
final MarianumConnectTokenStorage _tokenStorage;
|
||||
|
||||
AuthLogin({
|
||||
@@ -19,17 +17,7 @@ class AuthLogin extends MarianumConnectQuery {
|
||||
const MarianumConnectTokenStorage(),
|
||||
Dio? dio,
|
||||
}) : _tokenStorage = tokenStorage,
|
||||
super(dio: dio ?? _buildDio());
|
||||
|
||||
static Dio _buildDio() => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: _connectTimeout,
|
||||
receiveTimeout: _receiveTimeout,
|
||||
sendTimeout: _connectTimeout,
|
||||
responseType: ResponseType.json,
|
||||
contentType: 'application/json',
|
||||
),
|
||||
);
|
||||
super(dio: dio ?? MarianumConnectApi.plainDio());
|
||||
|
||||
Future<AuthLoginResponse> run({
|
||||
required String username,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../errors/auth_exception.dart';
|
||||
import '../../auth/token_storage.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Probes that the stored bearer token still maps to the given credentials.
|
||||
@@ -12,9 +13,6 @@ import '../../marianumconnect_query.dart';
|
||||
/// Bypasses the shared dio singleton so the auth interceptor doesn't kick in
|
||||
/// and obscure a real 401 with a silent re-login.
|
||||
class AuthVerify extends MarianumConnectQuery {
|
||||
static const Duration _connectTimeout = Duration(seconds: 10);
|
||||
static const Duration _receiveTimeout = Duration(seconds: 15);
|
||||
|
||||
final MarianumConnectTokenStorage _tokenStorage;
|
||||
|
||||
AuthVerify({
|
||||
@@ -22,17 +20,7 @@ class AuthVerify extends MarianumConnectQuery {
|
||||
const MarianumConnectTokenStorage(),
|
||||
Dio? dio,
|
||||
}) : _tokenStorage = tokenStorage,
|
||||
super(dio: dio ?? _buildDio());
|
||||
|
||||
static Dio _buildDio() => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: _connectTimeout,
|
||||
sendTimeout: _connectTimeout,
|
||||
receiveTimeout: _receiveTimeout,
|
||||
responseType: ResponseType.json,
|
||||
contentType: 'application/json',
|
||||
),
|
||||
);
|
||||
super(dio: dio ?? MarianumConnectApi.plainDio());
|
||||
|
||||
/// Throws [AuthException] on 401 (credentials no longer match the token's
|
||||
/// user, token missing, or token rejected), other [AppException]s on
|
||||
|
||||
@@ -7,8 +7,6 @@ import 'get_breakers_response.dart';
|
||||
class GetBreakers extends MarianumConnectQuery {
|
||||
GetBreakers({super.dio});
|
||||
|
||||
Future<GetBreakersResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(endpoint('breaker'));
|
||||
return GetBreakersResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<GetBreakersResponse> run() =>
|
||||
getObject('breaker', GetBreakersResponse.fromJson);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ import 'get_capabilities_response.dart';
|
||||
class GetCapabilities extends MarianumConnectQuery {
|
||||
GetCapabilities({super.dio});
|
||||
|
||||
Future<CapabilitiesResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('me/capabilities'),
|
||||
);
|
||||
return CapabilitiesResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<CapabilitiesResponse> run() =>
|
||||
getObject('me/capabilities', CapabilitiesResponse.fromJson);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,5 @@ import '../../models/mc_holiday.dart';
|
||||
class GetHolidays extends MarianumConnectQuery {
|
||||
GetHolidays({super.dio});
|
||||
|
||||
Future<List<McHoliday>> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(endpoint('holidays'));
|
||||
return response.data!
|
||||
.map((e) => McHoliday.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
});
|
||||
Future<List<McHoliday>> run() => getList('holidays', McHoliday.fromJson);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import 'get_ticker_response.dart';
|
||||
class GetTicker extends MarianumConnectQuery {
|
||||
GetTicker({super.dio});
|
||||
|
||||
Future<TickerResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(endpoint('ticker'));
|
||||
return TickerResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<TickerResponse> run() =>
|
||||
getObject('ticker', TickerResponse.fromJson);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,6 @@ import 'get_ticker_nav_response.dart';
|
||||
class GetTickerNav extends MarianumConnectQuery {
|
||||
GetTickerNav({super.dio});
|
||||
|
||||
Future<TickerNavResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('ticker/pages'),
|
||||
);
|
||||
return TickerNavResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<TickerNavResponse> run() =>
|
||||
getObject('ticker/pages', TickerNavResponse.fromJson);
|
||||
}
|
||||
|
||||
+4
-6
@@ -4,10 +4,8 @@ import '../../marianumconnect_query.dart';
|
||||
class TimetableCustomEventsGet extends MarianumConnectQuery {
|
||||
TimetableCustomEventsGet({super.dio});
|
||||
|
||||
Future<GetCustomTimetableEventResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/custom-events'),
|
||||
);
|
||||
return GetCustomTimetableEventResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<GetCustomTimetableEventResponse> run() => getObject(
|
||||
'timetable/custom-events',
|
||||
GetCustomTimetableEventResponse.fromJson,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ import 'timetable_get_classes_response.dart';
|
||||
class TimetableGetClasses extends MarianumConnectQuery {
|
||||
TimetableGetClasses({super.dio});
|
||||
|
||||
Future<TimetableGetClassesResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/classes'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimetableClass.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetClassesResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetClassesResponse> run() async =>
|
||||
TimetableGetClassesResponse(
|
||||
result: await getList(
|
||||
'timetable/elements/classes',
|
||||
McTimetableClass.fromJson,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
+5
-10
@@ -13,14 +13,9 @@ class TimetableGetElementWeek extends MarianumConnectQuery {
|
||||
required int id,
|
||||
required DateTime from,
|
||||
required DateTime until,
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/${type.pathSegment}/$id'),
|
||||
queryParameters: {'from': _format(from), 'until': _format(until)},
|
||||
);
|
||||
return TimetableGetWeekResponse.fromJson(response.data!);
|
||||
});
|
||||
|
||||
String _format(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
}) => getObject(
|
||||
'timetable/${type.pathSegment}/$id',
|
||||
TimetableGetWeekResponse.fromJson,
|
||||
queryParameters: {'from': isoDate(from), 'until': isoDate(until)},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,8 @@ import 'timetable_get_holidays_response.dart';
|
||||
class TimetableGetHolidays extends MarianumConnectQuery {
|
||||
TimetableGetHolidays({super.dio});
|
||||
|
||||
Future<TimetableGetHolidaysResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/holidays'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McHoliday.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetHolidaysResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetHolidaysResponse> run() async =>
|
||||
TimetableGetHolidaysResponse(
|
||||
result: await getList('timetable/holidays', McHoliday.fromJson),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,7 @@ import 'timetable_get_rooms_response.dart';
|
||||
class TimetableGetRooms extends MarianumConnectQuery {
|
||||
TimetableGetRooms({super.dio});
|
||||
|
||||
Future<TimetableGetRoomsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(endpoint('timetable/rooms'));
|
||||
final list = response.data!
|
||||
.map((e) => McRoom.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetRoomsResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetRoomsResponse> run() async => TimetableGetRoomsResponse(
|
||||
result: await getList('timetable/rooms', McRoom.fromJson),
|
||||
);
|
||||
}
|
||||
|
||||
+2
-6
@@ -4,10 +4,6 @@ import 'timetable_get_schoolyear_response.dart';
|
||||
class TimetableGetSchoolyear extends MarianumConnectQuery {
|
||||
TimetableGetSchoolyear({super.dio});
|
||||
|
||||
Future<TimetableGetSchoolyearResponse> run() => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/schoolyear'),
|
||||
);
|
||||
return TimetableGetSchoolyearResponse.fromJson(response.data!);
|
||||
});
|
||||
Future<TimetableGetSchoolyearResponse> run() =>
|
||||
getObject('timetable/schoolyear', TimetableGetSchoolyearResponse.fromJson);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ import 'timetable_get_students_response.dart';
|
||||
class TimetableGetStudents extends MarianumConnectQuery {
|
||||
TimetableGetStudents({super.dio});
|
||||
|
||||
Future<TimetableGetStudentsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/students'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimetableStudent.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetStudentsResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetStudentsResponse> run() async =>
|
||||
TimetableGetStudentsResponse(
|
||||
result: await getList(
|
||||
'timetable/elements/students',
|
||||
McTimetableStudent.fromJson,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,8 @@ import 'timetable_get_subjects_response.dart';
|
||||
class TimetableGetSubjects extends MarianumConnectQuery {
|
||||
TimetableGetSubjects({super.dio});
|
||||
|
||||
Future<TimetableGetSubjectsResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/subjects'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McSubject.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetSubjectsResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetSubjectsResponse> run() async =>
|
||||
TimetableGetSubjectsResponse(
|
||||
result: await getList('timetable/subjects', McSubject.fromJson),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ import 'timetable_get_teachers_response.dart';
|
||||
class TimetableGetTeachers extends MarianumConnectQuery {
|
||||
TimetableGetTeachers({super.dio});
|
||||
|
||||
Future<TimetableGetTeachersResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/elements/teachers'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimetableTeacherElement.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetTeachersResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetTeachersResponse> run() async =>
|
||||
TimetableGetTeachersResponse(
|
||||
result: await getList(
|
||||
'timetable/elements/teachers',
|
||||
McTimetableTeacherElement.fromJson,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,8 @@ import 'timetable_get_timegrid_response.dart';
|
||||
class TimetableGetTimegrid extends MarianumConnectQuery {
|
||||
TimetableGetTimegrid({super.dio});
|
||||
|
||||
Future<TimetableGetTimegridResponse> run() => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('timetable/timegrid'),
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McTimegridUnit.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return TimetableGetTimegridResponse(result: list);
|
||||
});
|
||||
Future<TimetableGetTimegridResponse> run() async =>
|
||||
TimetableGetTimegridResponse(
|
||||
result: await getList('timetable/timegrid', McTimegridUnit.fromJson),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,9 @@ class TimetableGetWeek extends MarianumConnectQuery {
|
||||
Future<TimetableGetWeekResponse> run({
|
||||
required DateTime from,
|
||||
required DateTime until,
|
||||
}) => guard(() async {
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
endpoint('timetable/me'),
|
||||
queryParameters: {'from': _format(from), 'until': _format(until)},
|
||||
);
|
||||
return TimetableGetWeekResponse.fromJson(response.data!);
|
||||
});
|
||||
|
||||
String _format(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
}) => getObject(
|
||||
'timetable/me',
|
||||
TimetableGetWeekResponse.fromJson,
|
||||
queryParameters: {'from': isoDate(from), 'until': isoDate(until)},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,11 @@ import 'user_search_response.dart';
|
||||
class UserSearch extends MarianumConnectQuery {
|
||||
UserSearch({super.dio});
|
||||
|
||||
Future<UserSearchResponse> run(String query) => guard(() async {
|
||||
final response = await dio.get<List<dynamic>>(
|
||||
endpoint('users/search'),
|
||||
Future<UserSearchResponse> run(String query) async => UserSearchResponse(
|
||||
result: await getList(
|
||||
'users/search',
|
||||
McUserSearchResult.fromJson,
|
||||
queryParameters: {'q': query},
|
||||
);
|
||||
final list = response.data!
|
||||
.map((e) => McUserSearchResult.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return UserSearchResponse(result: list);
|
||||
});
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user