Skip to content

Commit

Permalink
Migrate app_functions package to null safety (#412)
Browse files Browse the repository at this point in the history
Closes #209
  • Loading branch information
nilsreichardt authored Mar 4, 2023
1 parent 2a8ab89 commit 958ad1f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 70 deletions.
14 changes: 6 additions & 8 deletions lib/app_functions/lib/src/app_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@

import 'package:app_functions/exceptions.dart';
import 'package:app_functions/src/app_functions_result.dart';

import 'package:cloud_functions/cloud_functions.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';

class AppFunctions {
final FirebaseFunctions _firebaseFunctions;

AppFunctions(this._firebaseFunctions);

Future<AppFunctionsResult<T>> callCloudFunction<T>(
{@required String functionName,
@required Map<String, dynamic> parameters}) async {
Future<AppFunctionsResult<T>> callCloudFunction<T>({
required String functionName,
required Map<String, dynamic> parameters,
}) async {
try {
final httpsCallableResult =
await _firebaseFunctions.httpsCallable(functionName).call(parameters);
Expand All @@ -47,7 +45,7 @@ class AppFunctions {
FirebaseFunctionsException cloudFunctionsException) {
print("Code: " + cloudFunctionsException.code);
print("Details: " + cloudFunctionsException.details);
print("Message: " + cloudFunctionsException.message);
print("Message: ${cloudFunctionsException.message}");
if (cloudFunctionsException.code == 'DeadlineExceeded')
return TimeoutAppFunctionsException();

Expand All @@ -59,7 +57,7 @@ class AppFunctions {
if (platformException.code == '-1009')
return NoInternetAppFunctionsException();
print("Code: " + platformException.code);
print("Message: " + platformException.message);
print("Message: ${platformException.message}");

return UnknownAppFunctionsException(platformException);
}
Expand Down
17 changes: 8 additions & 9 deletions lib/app_functions/lib/src/app_functions_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:flutter/material.dart';

import 'app_functions_exceptions.dart';

/// Das Result Objekt nach Aufruf einer AppFunction.
/// Es enthält entweder Daten oder eine [AppFunctionsException].
/// Über hasData oder hasException kann dies ermittelt werden.
class AppFunctionsResult<T> {
final T data;
final AppFunctionsException exception;
final T? data;
final AppFunctionsException? exception;
final bool hasData, hasException;

AppFunctionsResult._(
{@required this.data,
@required this.exception,
@required this.hasData,
@required this.hasException});
AppFunctionsResult._({
required this.data,
required this.exception,
required this.hasData,
required this.hasException,
});

factory AppFunctionsResult.data(T data) {
return AppFunctionsResult._(
Expand Down
8 changes: 4 additions & 4 deletions lib/app_functions/lib/src/app_functions_web_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// SPDX-License-Identifier: EUPL-1.2

import 'package:app_functions/app_functions.dart';
import 'package:meta/meta.dart';

Future<AppFunctionsResult> callCloudFunctionWeb(
{@required String functionName,
@required Map<String, dynamic> parameters}) async {
Future<AppFunctionsResult> callCloudFunctionWeb({
required String functionName,
required Map<String, dynamic> parameters,
}) async {
throw UnimplementedError();
}
112 changes: 66 additions & 46 deletions lib/app_functions/lib/src/sharezone_app_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
// SPDX-License-Identifier: EUPL-1.2

import 'package:app_functions/app_functions.dart';
import 'package:meta/meta.dart';

class SharezoneAppFunctions {
final AppFunctions _appFunctions;

SharezoneAppFunctions(this._appFunctions);

Future<AppFunctionsResult<dynamic>> joinGroupByValue({
@required String enteredValue,
@required String memberID,
List<String> coursesForSchoolClass,
required String enteredValue,
required String memberID,
List<String>? coursesForSchoolClass,
int version = 2,
}) {
return _appFunctions
Expand All @@ -29,8 +28,9 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<dynamic>> enterActivationCode(
{@required String enteredActivationCode}) {
Future<AppFunctionsResult<dynamic>> enterActivationCode({
required String enteredActivationCode,
}) {
return _appFunctions
.callCloudFunction(functionName: 'EnterActivationCode', parameters: {
'activationCodeID': enteredActivationCode,
Expand All @@ -40,9 +40,9 @@ class SharezoneAppFunctions {
/// Beitreten einer Gruppe mittels einer Id. Dies ist zum Beispiel beim Beitreten eines
/// Kurses in einer Klasse der Fall.
Future<AppFunctionsResult<bool>> joinWithGroupId({
@required String id,
@required String type,
@required String uId,
required String id,
required String type,
required String uId,
}) {
return _appFunctions
.callCloudFunction(functionName: 'JoinWithGroupId', parameters: {
Expand All @@ -52,19 +52,23 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> leave(
{@required String id, @required String type, @required String memberID}) {
Future<AppFunctionsResult<bool>> leave({
required String id,
required String type,
required String memberID,
}) {
return _appFunctions.callCloudFunction(functionName: 'Leave', parameters: {
'id': id,
'type': type,
'memberID': memberID,
});
}

Future<AppFunctionsResult<bool>> groupEdit(
{@required String id,
@required String type,
@required Map<String, dynamic> data}) {
Future<AppFunctionsResult<bool>> groupEdit({
required String id,
required String type,
required Map<String, dynamic> data,
}) {
return _appFunctions
.callCloudFunction(functionName: 'GroupEdit', parameters: {
'id': id,
Expand All @@ -73,10 +77,11 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> groupEditSettings(
{@required String id,
@required String type,
@required Map<String, dynamic> settings}) {
Future<AppFunctionsResult<bool>> groupEditSettings({
required String id,
required String type,
required Map<String, dynamic> settings,
}) {
return _appFunctions
.callCloudFunction(functionName: 'GroupEditSettings', parameters: {
'id': id,
Expand All @@ -85,8 +90,10 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> generateNewMeetingID(
{@required String id, @required String type}) {
Future<AppFunctionsResult<bool>> generateNewMeetingID({
required String id,
required String type,
}) {
return _appFunctions.callCloudFunction(
functionName: 'GenerateNewGroupMeetingID',
parameters: {
Expand All @@ -95,10 +102,11 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> groupDelete(
{@required String groupID,
@required String type,
String schoolClassDeleteType}) {
Future<AppFunctionsResult<bool>> groupDelete({
required String groupID,
required String type,
String? schoolClassDeleteType,
}) {
return _appFunctions
.callCloudFunction(functionName: 'GroupDelete', parameters: {
'id': groupID,
Expand All @@ -107,11 +115,12 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> groupCreate(
{@required String id,
@required String memberID,
@required String type,
@required Map<String, dynamic> data}) {
Future<AppFunctionsResult<bool>> groupCreate({
required String id,
required String memberID,
required String type,
required Map<String, dynamic> data,
}) {
return _appFunctions
.callCloudFunction(functionName: 'GroupCreate', parameters: {
'memberID': memberID,
Expand All @@ -121,20 +130,23 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> userUpdate(
{@required String userID, @required Map<String, dynamic> userData}) {
Future<AppFunctionsResult<bool>> userUpdate({
required String userID,
required Map<String, dynamic> userData,
}) {
return _appFunctions
.callCloudFunction(functionName: 'UserUpdate', parameters: {
'userID': userID,
'userData': userData,
});
}

Future<AppFunctionsResult<bool>> memberUpdateRole(
{@required String memberID,
@required String id,
@required String role,
@required String type}) {
Future<AppFunctionsResult<bool>> memberUpdateRole({
required String memberID,
required String id,
required String role,
required String type,
}) {
return _appFunctions
.callCloudFunction(functionName: 'MemberUpdateRole', parameters: {
'memberID': memberID,
Expand All @@ -144,42 +156,50 @@ class SharezoneAppFunctions {
});
}

Future<AppFunctionsResult<bool>> userDelete({@required String userID}) {
Future<AppFunctionsResult<bool>> userDelete({required String userID}) {
return _appFunctions
.callCloudFunction(functionName: 'UserDelete', parameters: {
'userID': userID,
});
}

Future<AppFunctionsResult<bool>> schoolClassAddCourse(
{@required String schoolClassID, @required String courseID}) {
Future<AppFunctionsResult<bool>> schoolClassAddCourse({
required String schoolClassID,
required String courseID,
}) {
return _appFunctions
.callCloudFunction(functionName: 'SchoolClassAddCourse', parameters: {
'schoolClassID': schoolClassID,
'courseID': courseID,
});
}

Future<AppFunctionsResult<bool>> schoolClassRemoveCourse(
{@required String schoolClassID, @required String courseID}) {
Future<AppFunctionsResult<bool>> schoolClassRemoveCourse({
required String schoolClassID,
required String courseID,
}) {
return _appFunctions
.callCloudFunction(functionName: 'SchoolClassAddCourse', parameters: {
'schoolClassID': schoolClassID,
'courseID': courseID,
});
}

Future<AppFunctionsResult<bool>> authenticateUserViaQrCodeId(
{@required String uid, @required String qrId}) async {
Future<AppFunctionsResult<bool>> authenticateUserViaQrCodeId({
required String uid,
required String qrId,
}) async {
return _appFunctions
.callCloudFunction(functionName: 'QrCodeSignInAssignUID', parameters: {
'qrID': qrId,
'uid': uid,
});
}

Future<AppFunctionsResult<Map<String, dynamic>>> loadHolidays(
{@required String stateCode, @required String year}) {
Future<AppFunctionsResult<Map<String, dynamic>>> loadHolidays({
required String stateCode,
required String year,
}) {
return _appFunctions
.callCloudFunction(functionName: 'loadHolidays', parameters: {
'stateCode': stateCode,
Expand Down
4 changes: 1 addition & 3 deletions lib/app_functions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version: 0.0.1
publish_to: none

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand All @@ -22,5 +22,3 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter

flutter: null

0 comments on commit 958ad1f

Please sign in to comment.