Skip to content

Commit

Permalink
fix: login and refactor code architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
therajanmaurya committed Jan 28, 2024
1 parent 677c7e2 commit 6e17bbb
Show file tree
Hide file tree
Showing 75 changed files with 2,100 additions and 546 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
}

dependencies {
add("implementation", project(":main-core:ui"))
add("implementation", project(":main-core:designsystem"))

add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ plugins {
alias(libs.plugins.roborazzi) apply false
alias(libs.plugins.secrets) apply false
alias(libs.plugins.room) apply false
alias(libs.plugins.kotlin.android) apply false
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
package org.mifos.mobilewallet.core.data.fineract.api;
package org.mifos.mobilewallet.core.data.fineract.api

import android.text.TextUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Request.Builder;
import okhttp3.Response;
import android.text.TextUtils
import okhttp3.Interceptor
import okhttp3.Response
import org.mifos.mobilewallet.core.data.fineract.local.PreferencesHelper
import java.io.IOException

/**
* Created by naman on 17/6/17.
*/

public class ApiInterceptor implements Interceptor {

public static final String HEADER_TENANT = "Fineract-Platform-TenantId";
public static final String HEADER_AUTH = "Authorization";
private String authToken;
private String headerTenant;

public ApiInterceptor(String authToken, String headerTenant) {
this.authToken = authToken;
this.headerTenant = headerTenant;
}

@Override
public Response intercept(Chain chain) throws IOException {
Request chainRequest = chain.request();
Builder builder = chainRequest.newBuilder()
.header(HEADER_TENANT, headerTenant);

if (!TextUtils.isEmpty(authToken)) {
builder.header(HEADER_AUTH, authToken);
class ApiInterceptor(val preferencesHelper: PreferencesHelper) : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val chainRequest = chain.request()
val builder = chainRequest.newBuilder().header(HEADER_TENANT, DEFAULT)
val authToken = preferencesHelper.token
if (!authToken.isNullOrEmpty()) {
builder.header(HEADER_AUTH, authToken)
}
val request = builder.build()
return chain.proceed(request)
}

Request request = builder.build();
return chain.proceed(request);
companion object {
const val HEADER_TENANT = "Fineract-Platform-TenantId"
const val HEADER_AUTH = "Authorization"
const val DEFAULT = "default"
}
}
Original file line number Diff line number Diff line change
@@ -1,190 +1,90 @@
package org.mifos.mobilewallet.core.data.fineract.api;

import android.util.Base64;

import org.mifos.mobilewallet.core.data.fineract.api.services.AccountTransfersService;
import org.mifos.mobilewallet.core.data.fineract.api.services.AuthenticationService;
import org.mifos.mobilewallet.core.data.fineract.api.services.ClientService;
import org.mifos.mobilewallet.core.data.fineract.api.services.DocumentService;
import org.mifos.mobilewallet.core.data.fineract.api.services.InvoiceService;
import org.mifos.mobilewallet.core.data.fineract.api.services.KYCLevel1Service;
import org.mifos.mobilewallet.core.data.fineract.api.services.NotificationService;
import org.mifos.mobilewallet.core.data.fineract.api.services.RegistrationService;
import org.mifos.mobilewallet.core.data.fineract.api.services.RunReportService;
import org.mifos.mobilewallet.core.data.fineract.api.services.SavedCardService;
import org.mifos.mobilewallet.core.data.fineract.api.services.SavingsAccountsService;
import org.mifos.mobilewallet.core.data.fineract.api.services.SearchService;
import org.mifos.mobilewallet.core.data.fineract.api.services.StandingInstructionService;
import org.mifos.mobilewallet.core.data.fineract.api.services.ThirdPartyTransferService;
import org.mifos.mobilewallet.core.data.fineract.api.services.TwoFactorAuthService;
import org.mifos.mobilewallet.core.data.fineract.api.services.UserService;
import org.mifos.mobilewallet.core.utils.Constants;

import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
package org.mifos.mobilewallet.core.data.fineract.api

import org.mifos.mobilewallet.core.data.fineract.api.services.AccountTransfersService
import org.mifos.mobilewallet.core.data.fineract.api.services.AuthenticationService
import org.mifos.mobilewallet.core.data.fineract.api.services.ClientService
import org.mifos.mobilewallet.core.data.fineract.api.services.DocumentService
import org.mifos.mobilewallet.core.data.fineract.api.services.InvoiceService
import org.mifos.mobilewallet.core.data.fineract.api.services.KYCLevel1Service
import org.mifos.mobilewallet.core.data.fineract.api.services.NotificationService
import org.mifos.mobilewallet.core.data.fineract.api.services.RegistrationService
import org.mifos.mobilewallet.core.data.fineract.api.services.RunReportService
import org.mifos.mobilewallet.core.data.fineract.api.services.SavedCardService
import org.mifos.mobilewallet.core.data.fineract.api.services.SavingsAccountsService
import org.mifos.mobilewallet.core.data.fineract.api.services.SearchService
import org.mifos.mobilewallet.core.data.fineract.api.services.StandingInstructionService
import org.mifos.mobilewallet.core.data.fineract.api.services.ThirdPartyTransferService
import org.mifos.mobilewallet.core.data.fineract.api.services.TwoFactorAuthService
import org.mifos.mobilewallet.core.data.fineract.api.services.UserService
import javax.inject.Inject

/**
* Created by naman on 17/6/17.
*/
class FineractApiManager @Inject constructor(
private val authenticationService: AuthenticationService,
private val clientService: ClientService,
private val savingsAccountsService: SavingsAccountsService,
private val registrationService: RegistrationService,
private val searchService: SearchService,
private val documentService: DocumentService,
private val runReportService: RunReportService,
private val twoFactorAuthService: TwoFactorAuthService,
private val accountTransfersService: AccountTransfersService,
private val savedCardService: SavedCardService,
private val kYCLevel1Service: KYCLevel1Service,
private val invoiceService: InvoiceService,
private val userService: UserService,
private val thirdPartyTransferService: ThirdPartyTransferService,
private val standingInstructionService: StandingInstructionService,
private val notificationService: NotificationService,
) {

public class FineractApiManager {

public static final String DEFAULT = "default";
public static final String BASIC = "Basic ";
private static BaseURL baseUrl = new BaseURL();
private static final String BASE_URL = baseUrl.getUrl();

private static Retrofit retrofit;
private static AuthenticationService authenticationApi;
private static ClientService clientsApi;
private static SavingsAccountsService savingsAccountsApi;
private static RegistrationService registrationAPi;
private static SearchService searchApi;
private static SavedCardService savedCardApi;
private static DocumentService documentApi;
private static TwoFactorAuthService twoFactorAuthApi;
private static AccountTransfersService accountTransfersApi;
private static RunReportService runReportApi;
private static KYCLevel1Service kycLevel1Api;
private static InvoiceService invoiceApi;
private static UserService userApi;
private static ThirdPartyTransferService thirdPartyTransferApi;
private static NotificationService notificationApi;
private static StandingInstructionService standingInstructionService;
private static SelfServiceApiManager sSelfInstance;

public FineractApiManager() {
String authToken = BASIC + Base64.encodeToString(Constants.MIFOS_PASSWORD
.getBytes(Charset.forName("UTF-8")), Base64.NO_WRAP);
createService(authToken);

if (sSelfInstance == null) {
sSelfInstance = new SelfServiceApiManager();
}
}

private static void init() {
authenticationApi = createApi(AuthenticationService.class);
clientsApi = createApi(ClientService.class);
savingsAccountsApi = createApi(SavingsAccountsService.class);
registrationAPi = createApi(RegistrationService.class);
searchApi = createApi(SearchService.class);
savedCardApi = createApi(SavedCardService.class);
documentApi = createApi(DocumentService.class);
twoFactorAuthApi = createApi(TwoFactorAuthService.class);
accountTransfersApi = createApi(AccountTransfersService.class);
runReportApi = createApi(RunReportService.class);
kycLevel1Api = createApi(KYCLevel1Service.class);
invoiceApi = createApi(InvoiceService.class);
userApi = createApi(UserService.class);
thirdPartyTransferApi = createApi(ThirdPartyTransferService.class);
notificationApi = createApi(NotificationService.class);
standingInstructionService = createApi(StandingInstructionService.class);
}

private static <T> T createApi(Class<T> clazz) {
return retrofit.create(clazz);
}

public static void createService(String authToken) {

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.addInterceptor(new ApiInterceptor(authToken, DEFAULT))
.build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.client(okHttpClient)
.build();

init();
}

public static void createSelfService(String authToken) {
SelfServiceApiManager.createService(authToken);
}

public static SelfServiceApiManager getSelfApiManager() {
return sSelfInstance;
}

public AuthenticationService getAuthenticationApi() {
return authenticationApi;
}

public ClientService getClientsApi() {
return clientsApi;
}

public SavingsAccountsService getSavingAccountsListApi() {
return savingsAccountsApi;
}

public RegistrationService getRegistrationAPi() {
return registrationAPi;
}

public SearchService getSearchApi() {
return searchApi;
}

public DocumentService getDocumentApi() {
return documentApi;
}

public RunReportService getRunReportApi() {
return runReportApi;
}

public TwoFactorAuthService getTwoFactorAuthApi() {
return twoFactorAuthApi;
}

public AccountTransfersService getAccountTransfersApi() {
return accountTransfersApi;
}

public SavedCardService getSavedCardApi() {
return savedCardApi;
}

public KYCLevel1Service getKycLevel1Api() {
return kycLevel1Api;
}

public InvoiceService getInvoiceApi() {
return invoiceApi;
}

public UserService getUserApi() {
return userApi;
}

public ThirdPartyTransferService getThirdPartyTransferApi() {
return thirdPartyTransferApi;
}

public NotificationService getNotificationApi() {
return notificationApi;
}

public StandingInstructionService getStandingInstructionApi() {
return standingInstructionService;
}
val authenticationApi: AuthenticationService
get() = authenticationService

val clientsApi: ClientService
get() = clientService

val registrationAPi: RegistrationService
get() = registrationService

val searchApi: SearchService
get() = searchService

val documentApi: DocumentService
get() = documentService

val runReportApi: RunReportService
get() = runReportService

val twoFactorAuthApi: TwoFactorAuthService
get() = twoFactorAuthService

val accountTransfersApi: AccountTransfersService
get() = accountTransfersService

val savedCardApi: SavedCardService
get() = savedCardService

val kycLevel1Api: KYCLevel1Service
get() = kYCLevel1Service

val invoiceApi: InvoiceService
get() = invoiceService

val userApi: UserService
get() = userService

val thirdPartyTransferApi: ThirdPartyTransferService
get() = thirdPartyTransferService

val notificationApi: NotificationService
get() = notificationService

val savingsAccountsApi: SavingsAccountsService
get() = savingsAccountsService

val standingInstructionApi: StandingInstructionService
get() = standingInstructionService
}
Loading

0 comments on commit 6e17bbb

Please sign in to comment.