Skip to content

Commit

Permalink
Merge pull request #8 from demola234:ci/cd
Browse files Browse the repository at this point in the history
Ci/cd
  • Loading branch information
demola234 committed Aug 27, 2023
2 parents fd4ff8b + faaf551 commit 6b67cce
Show file tree
Hide file tree
Showing 64 changed files with 3,936 additions and 1,758 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Main

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
name: unit-test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
- uses: subosito/[email protected]
with:
flutter_channel: stable
flutter_version: 3.0.0
- name: Install dependencies
run: flutter pub get
- name: Build APK
run: flutter build apk --split-per-abi
- name: Run unit tests
run: flutter test --coverage
- name: Upload to code coverage
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coverage/lcov.info
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# defiraiser_mobile
# DefiFundr

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
[![CI](https://github.com/demola234/tdd_weather/actions/workflows/cl.yml/badge.svg)](https://github.com/demola234/tdd_weather/actions/workflows/cl.yml)
[![codecov](https://codecov.io/gh/demola234/tdd_weather/branch/main/graph/badge.svg?token=IPGEQHNLN2)](https://codecov.io/gh/demola234/tdd_weather)
55 changes: 45 additions & 10 deletions lib/core/network/network_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import 'package:curl_logger_dio_interceptor/curl_logger_dio_interceptor.dart';
// 🌎 Project imports:
import 'package:defiraiser_mobile/core/network/api_error.dart';
import 'package:defiraiser_mobile/core/secure/secure_key.dart';
import 'package:dio/dio.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';

import '../di/injector.dart';
import '../secure/secure.dart';

abstract class NetworkProvider {
Future<Response?> call({
required String path,
Expand Down Expand Up @@ -63,28 +67,59 @@ class NetworkProviderImpl extends NetworkProvider {
Options? options,
Map<String, dynamic> queryParams = const {},
}) async {
final token =
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token);
Response? response;
try {
switch (method) {
case RequestMethod.get:
response = await _getDioInstance()
.get(path, queryParameters: queryParams, options: options);
response = await _getDioInstance().get(
path,
queryParameters: queryParams,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
break;
case RequestMethod.post:
response = await _getDioInstance().post(path,
data: body, queryParameters: queryParams, options: options);
response = await _getDioInstance().post(
path,
data: body,
queryParameters: queryParams,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
break;
case RequestMethod.patch:
response = await _getDioInstance().patch(path,
data: body, queryParameters: queryParams, options: options);
response = await _getDioInstance().patch(
path,
data: body,
queryParameters: queryParams,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
break;
case RequestMethod.put:
response = await _getDioInstance().put(path,
data: body, queryParameters: queryParams, options: options);
response = await _getDioInstance().put(
path,
data: body,
queryParameters: queryParams,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
break;
case RequestMethod.delete:
response = await _getDioInstance().delete(path,
data: body, queryParameters: queryParams, options: options);
response = await _getDioInstance().delete(
path,
data: body,
queryParameters: queryParams,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
break;
}

Expand Down
9 changes: 1 addition & 8 deletions lib/core/secure/secure_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ class ISecureStorage implements SecureStorage {
Future<String?> getHiveKey(String hiveKey) async {
return await _flutterSecureStorage.read(
key: hiveKey,
aOptions: AndroidOptions(
encryptedSharedPreferences: true,
keyCipherAlgorithm:
KeyCipherAlgorithm.RSA_ECB_OAEPwithSHA_256andMGF1Padding),
iOptions: IOSOptions(
synchronizable: true,
accessibility: KeychainAccessibility.first_unlock,
),

);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class AuthLocalDataSource {
required LastUserCachedDetails lastUserCachedDetails,
});

Future<void> cacheUserDetails({
cacheUserDetails({
required UserResponse user,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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/authentication/domain/entities/check_user_entity/check_user_entity.dart';
import 'package:defiraiser_mobile/features/authentication/domain/entities/login_entity/login_response_entity.dart';
import 'package:defiraiser_mobile/features/authentication/domain/entities/register_entity/create_account_response.dart';
import 'package:dio/dio.dart';

abstract class AuthenticationRemoteDataSource {
Future<CreateAccountResponse> createAccount(String username, String email);
Expand Down Expand Up @@ -177,16 +173,10 @@ class IAuthenticationRemoteDataSource

@override
Future<UserResponse> setProfile({required int imageId}) async {
final token =
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token);

final response = await client.call(
path: EndpointManager.setProfileAvatar,
method: RequestMethod.post,
body: {'image_id': imageId},
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
final res = response!.data['data'];
if (response.statusCode == 200) {
Expand All @@ -198,15 +188,9 @@ class IAuthenticationRemoteDataSource

@override
Future<UserResponse> getUserDetails() async {
final token =
await sl<SecureStorage>().getAccessToken(SecureStorageKey().token);

final response = await client.call(
path: EndpointManager.getUser,
method: RequestMethod.get,
options: Options(headers: {
'Authorization': 'Bearer $token',
}),
);
final res = response!.data['data'];
if (response.statusCode == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ class IAuthenticationRepository implements AuthenticationRepository {
{required String username, required String password}) async {
try {
final remoteLogin = await remoteDataSource.login(username, password);
final lastCacheDetails = LastUserCachedDetails(
password: password,
username: username,
email: remoteLogin.data!.user.email,
isBiometric: remoteLogin.data!.user.biometrics,
);
await authLocalDataSource.cacheUserLoginData(
lastUserCachedDetails: lastCacheDetails);
await authLocalDataSource.cacheUserDetails(user: remoteLogin.data!.user);
await authLocalDataSource.saveAccessToken(
token: remoteLogin.data!.accessToken);
if (remoteLogin.data != null) {
final lastCacheDetails = LastUserCachedDetails(
password: password,
username: username,
email: remoteLogin.data!.user.email,
isBiometric: remoteLogin.data!.user.biometrics,
);
await authLocalDataSource.cacheUserLoginData(
lastUserCachedDetails: lastCacheDetails);
await authLocalDataSource.cacheUserDetails(
user: remoteLogin.data!.user);
await authLocalDataSource.saveAccessToken(
token: remoteLogin.data!.accessToken);
}
return Right(remoteLogin);
} on ApiError catch (error) {
return Left(error);
Expand Down

This file was deleted.

Loading

0 comments on commit 6b67cce

Please sign in to comment.