-
Notifications
You must be signed in to change notification settings - Fork 1
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 demola234/ui_implementation
unit tests
- Loading branch information
Showing
40 changed files
with
4,103 additions
and
232 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
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
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
107 changes: 103 additions & 4 deletions
107
lib/features/profile/data/data_source/profile_remote_date_source.dart
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,17 +1,116 @@ | ||
import 'package:defiraiser_mobile/core/di/injector.dart'; | ||
import 'package:defiraiser_mobile/core/global/error/exceptions.dart'; | ||
import 'package:defiraiser_mobile/core/network/endpoint_manager.dart'; | ||
import 'package:defiraiser_mobile/core/network/network_provider.dart'; | ||
import 'package:defiraiser_mobile/core/secure/secure.dart'; | ||
import 'package:defiraiser_mobile/core/secure/secure_key.dart'; | ||
import 'package:defiraiser_mobile/features/authentication/domain/entities/base_entity/base_entity.dart'; | ||
import 'package:defiraiser_mobile/features/profile/domain/entities/address_entity/address_entity.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
abstract class ProfileRemoteDataSource { | ||
Future<BaseEntity> setBiometrics(); | ||
Future<BaseEntity> setBiometrics({required bool biometrics}); | ||
Future<BaseEntity> changeUsername({required String username}); | ||
Future<BaseEntity> changePassword( | ||
{required String oldPassword, required String newPassword}); | ||
Future<AddressEntity> getPrivateKey({required String password}); | ||
} | ||
|
||
class ProfileRemoteDataSoImpl implements ProfileRemoteDataSource { | ||
final NetworkProvider client; | ||
ProfileRemoteDataSoImpl(this.client); | ||
|
||
@override | ||
Future<BaseEntity> setBiometrics() { | ||
// TODO: implement setBiometrics | ||
throw UnimplementedError(); | ||
Future<BaseEntity> setBiometrics({required bool biometrics}) async { | ||
final token = | ||
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token); | ||
|
||
final response = await client.call( | ||
path: EndpointManager.setBiometrics, | ||
method: RequestMethod.post, | ||
body: { | ||
'biometrics': biometrics, | ||
}, | ||
options: Options(headers: { | ||
'Authorization': 'Bearer $token', | ||
}), | ||
); | ||
final res = response!.data; | ||
if (response.statusCode == 200) { | ||
return BaseEntity.fromJson(res); | ||
} else { | ||
throw ServerException(message: 'Server Error'); | ||
} | ||
} | ||
|
||
@override | ||
Future<BaseEntity> changeUsername({required String username}) async { | ||
final token = | ||
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token); | ||
|
||
final response = await client.call( | ||
path: EndpointManager.changeUsername, | ||
method: RequestMethod.post, | ||
body: { | ||
'username': username, | ||
}, | ||
options: Options(headers: { | ||
'Authorization': 'Bearer $token', | ||
}), | ||
); | ||
final res = response!.data; | ||
if (response.statusCode == 200) { | ||
return BaseEntity.fromJson(res); | ||
} else { | ||
throw ServerException(message: 'Server Error'); | ||
} | ||
} | ||
|
||
@override | ||
Future<BaseEntity> changePassword( | ||
{required String oldPassword, required String newPassword}) async { | ||
final token = | ||
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token); | ||
|
||
final response = await client.call( | ||
path: EndpointManager.changePassword, | ||
method: RequestMethod.post, | ||
body: { | ||
'old_password': oldPassword, | ||
'new_password': newPassword, | ||
}, | ||
options: Options(headers: { | ||
'Authorization': 'Bearer $token', | ||
}), | ||
); | ||
final res = response!.data; | ||
if (response.statusCode == 200) { | ||
return BaseEntity.fromJson(res); | ||
} else { | ||
throw ServerException(message: 'Server Error'); | ||
} | ||
} | ||
|
||
@override | ||
Future<AddressEntity> getPrivateKey({required String password}) async { | ||
final token = | ||
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token); | ||
|
||
final response = await client.call( | ||
path: EndpointManager.getPrivateKey, | ||
method: RequestMethod.post, | ||
body: { | ||
'password': password, | ||
}, | ||
options: Options(headers: { | ||
'Authorization': 'Bearer $token', | ||
}), | ||
); | ||
final res = response!.data; | ||
if (response.statusCode == 200) { | ||
return AddressEntity.fromJson(res); | ||
} else { | ||
throw ServerException(message: 'Server Error'); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
lib/features/profile/domain/entities/address_entity/address_entity.dart
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 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'dart:convert'; | ||
|
||
part 'address_entity.freezed.dart'; | ||
part 'address_entity.g.dart'; | ||
|
||
AddressEntity addressEntityFromJson(String str) => AddressEntity.fromJson(json.decode(str)); | ||
|
||
String addressEntityToJson(AddressEntity data) => json.encode(data.toJson()); | ||
|
||
@freezed | ||
class AddressEntity with _$AddressEntity { | ||
const factory AddressEntity({ | ||
required Data data, | ||
@Default('') message, | ||
required int status, | ||
}) = _AddressEntity; | ||
|
||
factory AddressEntity.fromJson(Map<String, dynamic> json) => _$AddressEntityFromJson(json); | ||
} | ||
|
||
@freezed | ||
class Data with _$Data { | ||
@JsonSerializable(explicitToJson: true, fieldRename: FieldRename.snake) | ||
const factory Data({ | ||
@Default('') address, | ||
@Default('') privateKey, | ||
}) = _Data; | ||
|
||
factory Data.fromJson(Map<String, dynamic> json) => _$DataFromJson(json); | ||
} |
Oops, something went wrong.