Skip to content

Commit

Permalink
modularize for transfer feature (unfinished)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moirand committed Aug 26, 2024
1 parent afa48f5 commit 9a0f7fc
Show file tree
Hide file tree
Showing 85 changed files with 2,171 additions and 825 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ class MainActivity : AppCompatActivity(), NavigationHandler, TokenHandler, UserH
}

override fun navigateToTransfer() {
TODO("Not yet implemented")
navController.navigate(R.id.dashboard_to_transfer_navigation)
}

override fun navigateQrisToTransfer() {
navController.navigate(R.id.qris_to_transfer_navigation)
}

// Implementasi TokenHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import com.synrgy7team4.bankingapps.di.appKoin
import com.synrgy7team4.di.feature_auth.authKoin
import com.synrgy7team4.di.feature_dashboard.dashboardKoin
import com.synrgy7team4.di.feature_mutasi.mutasiKoin
import com.synrgy7team4.di.feature_transfer.transferKoin
import com.synrgy7team4.feature_auth.viewmodel.authViewModelKoin
import com.synrgy7team4.feature_dashboard.viewmodel.dashboardViewModelKoin
import com.synrgy7team4.feature_mutasi.viewmodel.mutasiViewModelKoin
import com.synrgy7team4.feature_transfer.viewmodel.transferViewModelKoin
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
Expand All @@ -26,6 +28,8 @@ class MyApplication : Application() {
dashboardViewModelKoin,
mutasiKoin,
mutasiViewModelKoin,
transferKoin,
transferViewModelKoin
)
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/navigation/main_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<include app:graph="@navigation/feature_auth_navigation" />
<include app:graph="@navigation/feature_dashboard_navigation" />
<include app:graph="@navigation/feature_transfer_navigation" />

<action
android:id="@+id/auth_to_dashboard_navigation"
Expand All @@ -46,4 +47,12 @@
<action
android:id="@+id/dashboard_to_mutasi_navigation"
app:destination="@id/mutasiFragment"/>

<action
android:id="@+id/dashboard_to_transfer_navigation"
app:destination="@id/feature_transfer_navigation"/>

<action
android:id="@+id/qris_to_transfer_navigation"
app:destination="@id/transferInputFragment"/>
</navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ interface NavigationHandler {
fun navigateToDashboard()
fun navigateToMutasi()
fun navigateToTransfer()
fun navigateQrisToTransfer()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.synrgy7team4.data.feature_auth.datasource.remote.response.EmailCheckR
import com.synrgy7team4.data.feature_auth.datasource.remote.response.KtpNumberCheckResponse
import com.synrgy7team4.data.feature_auth.datasource.remote.response.LoginData
import com.synrgy7team4.data.feature_auth.datasource.remote.response.LoginResponse
import com.synrgy7team4.data.feature_auth.datasource.remote.response.OtpData
import com.synrgy7team4.data.feature_auth.datasource.remote.response.OtpResponse
import com.synrgy7team4.data.feature_auth.datasource.remote.response.PhoneNumberCheckResponse
import com.synrgy7team4.data.feature_auth.datasource.remote.response.RegisterData
Expand All @@ -15,7 +14,6 @@ import com.synrgy7team4.domain.feature_auth.model.response.EmailCheckResponseDom
import com.synrgy7team4.domain.feature_auth.model.response.KtpNumberCheckResponseDomain
import com.synrgy7team4.domain.feature_auth.model.response.LoginDataDomain
import com.synrgy7team4.domain.feature_auth.model.response.LoginResponseDomain
import com.synrgy7team4.domain.feature_auth.model.response.OtpDataDomain
import com.synrgy7team4.domain.feature_auth.model.response.OtpResponseDomain
import com.synrgy7team4.domain.feature_auth.model.response.PhoneNumberCheckResponseDomain
import com.synrgy7team4.domain.feature_auth.model.response.RegisterDataDomain
Expand Down Expand Up @@ -61,17 +59,9 @@ object FileUtils {
fun OtpResponse.toOtpResponseDomain(): OtpResponseDomain =
OtpResponseDomain(
success = success,
data = data,
message = message,
errors = errors
message = message
)

// private fun OtpData.toOtpDataDomain(): OtpDataDomain =
// OtpDataDomain(
// email = email ?: "",
// otp = otp ?: ""
// )

fun EmailCheckResponse.toEmailCheckResponseDomain(): EmailCheckResponseDomain =
EmailCheckResponseDomain(
success = success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ImplementAuthRemoteDatasource(
}

override suspend fun register(registerRequest: RegisterRequest): RegisterResponse =

try {
apiService.register(registerRequest)
} catch (e: HttpException) {
Expand All @@ -56,8 +55,6 @@ class ImplementAuthRemoteDatasource(
throw HttpExceptionUseCase(e, error.message)
}



override suspend fun verifyOtp(verifyOtpRequest: VerifyOtpRequest): OtpResponse =
try {
apiService.verifyOtp(verifyOtpRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ package com.synrgy7team4.data.feature_auth.datasource.remote.response
import com.google.gson.annotations.SerializedName

data class RegisterErrorResponse(

@field:SerializedName("success")
val success: Boolean? = null,

@field:SerializedName("errors")
val errors: String
)


data class OtpErrorResponse(
@field:SerializedName("success")
val success: Boolean? = null,

@field:SerializedName("message")
val message: String? = null

)
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ class ImplementAuthRepository(
override suspend fun sendOtp(sendOtpRequest: SendOtpRequest): OtpResponseDomain =
authRemoteSource.sendOtp(sendOtpRequest).toOtpResponseDomain()


override suspend fun verifyOtp(verifyOtpRequest: VerifyOtpRequest): OtpResponseDomain =
authRemoteSource.verifyOtp(verifyOtpRequest).toOtpResponseDomain()


override suspend fun login(loginRequest: LoginRequest): LoginResponseDomain =
authRemoteSource.login(loginRequest).toLoginResponseDomain()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.synrgy7team4.data.feature_dashboard.datasource.remote

import com.synrgy7team4.data.feature_dashboard.datasource.remote.response.BalanceGetResponse
import com.synrgy7team4.data.feature_dashboard.datasource.remote.retrofit.ApiService
import com.synrgy7team4.domain.feature_mutasi.usecase.HttpExceptionUseCase
import com.synrgy7team4.domain.feature_dashboard.usecase.HttpExceptionUseCase
import retrofit2.HttpException

class ImplementBalanceRemoteDatasource(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.synrgy7team4.data.feature_dashboard.datasource.remote.retrofit

import com.synrgy7team4.data.feature_dashboard.datasource.remote.response.BalanceGetResponse
import com.synrgy7team4.data.feature_dashboard.datasource.remote.response.BalanceSetResponse
import com.synrgy7team4.domain.feature_dashboard.model.request.BalanceSetRequest
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Query

interface ApiService {
Expand All @@ -15,10 +11,4 @@ interface ApiService {
@Header("Authorization") jwtToken: String,
@Query("accountNumber") accountNumber: String
): BalanceGetResponse

@POST("balance/set")
suspend fun setBalance(
@Header("Authorization") jwtToken: String,
@Body balanceSetRequest: BalanceSetRequest
): BalanceSetResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.synrgy7team4.data.feature_mutasi.datasource.remote

import com.synrgy7team4.data.feature_mutasi.datasource.remote.response.MutationGetResponse
import com.synrgy7team4.data.feature_mutasi.datasource.remote.retrofit.ApiService
import com.synrgy7team4.domain.feature_mutasi.usecase.HttpExceptionUseCase
import com.synrgy7team4.domain.feature_transfer.usecase.HttpExceptionUseCase
import retrofit2.HttpException

class ImplementMutationRemoteDatasource(
Expand Down
105 changes: 105 additions & 0 deletions data/src/main/java/com/synrgy7team4/data/feature_transfer/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.synrgy7team4.data.feature_transfer

import com.synrgy7team4.data.feature_transfer.datasource.remote.response.AccountSaveResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.BalanceGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.BalanceSetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.MutationGetData
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.MutationGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.SavedAccountGetData
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.SavedAccountsGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.TransferData
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.TransferResponse
import com.synrgy7team4.domain.feature_transfer.model.response.AccountSaveResponseDomain
import com.synrgy7team4.domain.feature_transfer.model.response.BalanceGetResponseDomain
import com.synrgy7team4.domain.feature_transfer.model.response.BalanceSetResponseDomain
import com.synrgy7team4.domain.feature_transfer.model.response.MutationGetDataDomain
import com.synrgy7team4.domain.feature_transfer.model.response.MutationGetResponseDomain
import com.synrgy7team4.domain.feature_transfer.model.response.SavedAccountGetDataDomain
import com.synrgy7team4.domain.feature_transfer.model.response.SavedAccountsGetResponseDomain
import com.synrgy7team4.domain.feature_transfer.model.response.TransferDataDomain
import com.synrgy7team4.domain.feature_transfer.model.response.TransferResponseDomain

object FileUtils {
fun TransferResponse.toDomain(): TransferResponseDomain =
TransferResponseDomain(
data = data?.toDomain(),
message = message,
success = success
)

private fun TransferData.toDomain(): TransferDataDomain =
TransferDataDomain(
amount = amount,
destinationBank = destinationBank,
description = description,
type = type,
accountFrom = accountFrom,
createdAt = createdAt,
accountTo = accountTo,
datetime = datetime,
balance = balance,
referenceNumber = referenceNumber,
nameAccountFrom = nameAccountFrom,
id = id,
nameAccountTo = nameAccountTo,
status = status
)

fun BalanceSetResponse.toDomain(): BalanceSetResponseDomain =
BalanceSetResponseDomain(
data = data,
message = message,
success = success
)

fun BalanceGetResponse.toDomain(): BalanceGetResponseDomain =
BalanceGetResponseDomain(
data = data,
message = message,
success = success
)

fun AccountSaveResponse.toDomain(): AccountSaveResponseDomain =
AccountSaveResponseDomain(
success = success,
message = message
)

fun SavedAccountsGetResponse.toDomain(): SavedAccountsGetResponseDomain =
SavedAccountsGetResponseDomain(
data = data?.map { it?.toDomain() } ?: emptyList(),
success = success,
message = message
)

private fun SavedAccountGetData.toDomain(): SavedAccountGetDataDomain =
SavedAccountGetDataDomain(
name = name,
id = id,
accountNumber = accountNumber
)

fun MutationGetResponse.toDomain(): MutationGetResponseDomain =
MutationGetResponseDomain(
data = data?.toDomain(),
success = success,
message = message
)

private fun MutationGetData.toDomain(): MutationGetDataDomain =
MutationGetDataDomain(
amount = amount,
currentBalance = currentBalance,
usernameTo = usernameTo,
description = description,
accountFromType = accountToType,
type = type,
usernameFrom = usernameFrom,
datetime = datetime,
accountTo = accountTo,
accountToType = accountToType,
id = id,
accountFrom = accountFrom,
status = status
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.synrgy7team4.data.feature_transfer.datasource.remote

import com.synrgy7team4.data.feature_transfer.datasource.remote.response.BalanceGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.BalanceSetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.AccountSaveResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.MutationGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.SavedAccountsGetResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.response.TransferResponse
import com.synrgy7team4.data.feature_transfer.datasource.remote.retrofit.ApiService
import com.synrgy7team4.domain.feature_transfer.model.request.BalanceSetRequest
import com.synrgy7team4.domain.feature_transfer.model.request.AccountSaveRequest
import com.synrgy7team4.domain.feature_transfer.model.request.TransferRequest
import com.synrgy7team4.domain.feature_transfer.model.response.MutationGetResponseDomain
import com.synrgy7team4.domain.feature_transfer.usecase.HttpExceptionUseCase
import retrofit2.HttpException

class RemoteDatasource(private val apiService: ApiService) {
suspend fun transfer(jwtToken: String, transferRequest: TransferRequest): TransferResponse =
try {
apiService.transfer(jwtToken, transferRequest)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}

suspend fun setBalance(jwtToken: String, balanceRequest: BalanceSetRequest): BalanceSetResponse =
try {
apiService.setBalance(jwtToken, balanceRequest)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}

suspend fun getBalance(jwtToken: String, accountNumber: String): BalanceGetResponse =
try {
apiService.getBalance(jwtToken, accountNumber)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}

suspend fun saveAccount(jwtToken: String, accountSaveRequest: AccountSaveRequest): AccountSaveResponse =
try {
apiService.saveAccount(jwtToken, accountSaveRequest)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}

suspend fun getSavedAccounts(jwtToken: String): SavedAccountsGetResponse =
try {
apiService.getSavedAccounts(jwtToken)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}

suspend fun getMutation(jwtToken: String, id: String): MutationGetResponse =
try {
apiService.getMutation(jwtToken, id)
} catch (e: HttpException) {
val errorCode = e.response()?.code()
if (errorCode == 403) {
throw HttpExceptionUseCase(e, "403 Forbidden")
} else {
throw HttpExceptionUseCase(e)
}
}
}
Loading

0 comments on commit 9a0f7fc

Please sign in to comment.