-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from SandroMaglione/6-functional-programming
Functional programming (`fpdart`) [6]
- Loading branch information
Showing
16 changed files
with
283 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
abstract class GetUserInformationFailure { | ||
const GetUserInformationFailure(); | ||
|
||
String get mapToErrorMessage { | ||
if (this is RequestGetUserInformationFailure) { | ||
return 'Error when getting user information'; | ||
} else if (this is ResponseFormatErrorGetUserInformationFailure) { | ||
return 'Invalid response'; | ||
} else if (this is JsonDecodeGetUserInformationFailure) { | ||
return 'Missing valid user information'; | ||
} | ||
|
||
return 'Unexpected error, please try again'; | ||
} | ||
} | ||
|
||
class RequestGetUserInformationFailure extends GetUserInformationFailure { | ||
final Object error; | ||
final StackTrace stackTrace; | ||
const RequestGetUserInformationFailure(this.error, this.stackTrace); | ||
} | ||
|
||
class ResponseFormatErrorGetUserInformationFailure | ||
extends GetUserInformationFailure { | ||
final dynamic response; | ||
const ResponseFormatErrorGetUserInformationFailure(this.response); | ||
} | ||
|
||
class JsonDecodeGetUserInformationFailure extends GetUserInformationFailure { | ||
final Map<String, dynamic> data; | ||
const JsonDecodeGetUserInformationFailure(this.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
abstract class LoginFailure { | ||
const LoginFailure(); | ||
|
||
String get mapToErrorMessage { | ||
final failure = this; | ||
if (failure is AuthErrorLoginFailure) { | ||
return failure.message; | ||
} else if (failure is ExecutionErrorLoginFailure) { | ||
return 'Error when making login request'; | ||
} else if (failure is MissingUserIdLoginFailure) { | ||
return 'Missing user information'; | ||
} | ||
|
||
return 'Unexpected error, please try again'; | ||
} | ||
} | ||
|
||
class AuthErrorLoginFailure extends LoginFailure { | ||
final String message; | ||
final String? statusCode; | ||
const AuthErrorLoginFailure(this.message, this.statusCode); | ||
} | ||
|
||
class ExecutionErrorLoginFailure extends LoginFailure { | ||
final Object error; | ||
final StackTrace stackTrace; | ||
const ExecutionErrorLoginFailure(this.error, this.stackTrace); | ||
} | ||
|
||
class MissingUserIdLoginFailure extends LoginFailure { | ||
const MissingUserIdLoginFailure(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
abstract class SignOutFailure { | ||
const SignOutFailure(); | ||
|
||
String get mapToErrorMessage { | ||
if (this is ExecutionErrorSignOutFailure) { | ||
return 'Error when making sign out request'; | ||
} | ||
|
||
return 'Unexpected error, please try again'; | ||
} | ||
} | ||
|
||
class ExecutionErrorSignOutFailure extends SignOutFailure { | ||
final Object error; | ||
final StackTrace stackTrace; | ||
const ExecutionErrorSignOutFailure(this.error, this.stackTrace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
abstract class UpdateUserInformationFailure { | ||
const UpdateUserInformationFailure(); | ||
|
||
String get mapToErrorMessage { | ||
if (this is RequestUpdateUserInformationFailure) { | ||
return 'Error when updating user information'; | ||
} | ||
|
||
return 'Unexpected error, please try again'; | ||
} | ||
} | ||
|
||
class RequestUpdateUserInformationFailure extends UpdateUserInformationFailure { | ||
final Object error; | ||
final StackTrace stackTrace; | ||
const RequestUpdateUserInformationFailure(this.error, this.stackTrace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import 'package:flutter_supabase_complete/app/failures/login_failure.dart'; | ||
import 'package:flutter_supabase_complete/app/failures/sign_out_failure.dart'; | ||
import 'package:fpdart/fpdart.dart'; | ||
|
||
abstract class AuthRepository { | ||
Future<String> signInEmailAndPassword(String email, String password); | ||
Future<String> signUpEmailAndPassword(String email, String password); | ||
TaskEither<LoginFailure, String> signInEmailAndPassword( | ||
String email, | ||
String password, | ||
); | ||
|
||
TaskEither<LoginFailure, String> signUpEmailAndPassword( | ||
String email, | ||
String password, | ||
); | ||
|
||
Future<void> signOut(); | ||
TaskEither<SignOutFailure, Unit> signOut(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import 'package:flutter_supabase_complete/app/failures/get_user_information_failure.dart'; | ||
import 'package:flutter_supabase_complete/app/failures/update_user_information_failure.dart'; | ||
import 'package:flutter_supabase_complete/app/models/user_model.dart'; | ||
import 'package:fpdart/fpdart.dart'; | ||
|
||
abstract class UserDatabaseRepository { | ||
Future<UserModel> getUserInformation(String userId); | ||
Future<UserModel> updateUserInformation(UserModel userModel); | ||
TaskEither<GetUserInformationFailure, UserModel> getUserInformation( | ||
String userId, | ||
); | ||
|
||
TaskEither<UpdateUserInformationFailure, UserModel> updateUserInformation( | ||
UserModel userModel, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.