-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modularize for transfer feature (unfinished)
- Loading branch information
Showing
85 changed files
with
2,171 additions
and
825 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
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
105 changes: 105 additions & 0 deletions
105
data/src/main/java/com/synrgy7team4/data/feature_transfer/FileUtils.kt
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,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 | ||
) | ||
} |
89 changes: 89 additions & 0 deletions
89
...rc/main/java/com/synrgy7team4/data/feature_transfer/datasource/remote/RemoteDatasource.kt
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,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) | ||
} | ||
} | ||
} |
Oops, something went wrong.