27 lines
870 B
Dart
27 lines
870 B
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../../errors/marianumconnect_error.dart';
|
|
import '../../marianumconnect_api.dart';
|
|
import '../../marianumconnect_endpoint.dart';
|
|
import 'get_breakers_response.dart';
|
|
|
|
/// Fetches the app maintenance breaker rules from `GET /api/mobile/v1/breaker`.
|
|
/// The endpoint is public: the bearer token is attached if present but not
|
|
/// required, so this also works before login (e.g. to block the whole app).
|
|
class GetBreakers {
|
|
final Dio _dio;
|
|
|
|
GetBreakers({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
|
|
|
Future<GetBreakersResponse> run() async {
|
|
try {
|
|
final response = await _dio.get<Map<String, dynamic>>(
|
|
MarianumConnectEndpoint.resolve('breaker'),
|
|
);
|
|
return GetBreakersResponse.fromJson(response.data!);
|
|
} on DioException catch (e) {
|
|
throw mapMarianumConnectError(e);
|
|
}
|
|
}
|
|
}
|