Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature(savingsAccount): preview functionality impl, handle submit sa…
…vings application, navigation to details screen.
  • Loading branch information
sam-arth07 committed Oct 23, 2025
commit 49ef3c661d6d78b3b1129ed6511c20e8d25c0eb7
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ package com.mifos.core.data.repository
import com.mifos.core.common.utils.DataState
import com.mifos.core.model.objects.organisations.ProductSavings
import com.mifos.core.model.objects.payloads.SavingsPayload
import com.mifos.room.entities.client.Savings
import com.mifos.room.entities.templates.savings.SavingProductsTemplate
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -35,5 +35,5 @@ interface SavingsAccountRepository {
productId: Int,
): Flow<DataState<SavingProductsTemplate>>

fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<DataState<Savings>>
fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<DataState<HttpResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.mifos.core.data.repository.SavingsAccountRepository
import com.mifos.core.model.objects.organisations.ProductSavings
import com.mifos.core.model.objects.payloads.SavingsPayload
import com.mifos.core.network.datamanager.DataManagerSavings
import com.mifos.room.entities.client.Savings
import com.mifos.room.entities.templates.savings.SavingProductsTemplate
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.flow.Flow

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ class SavingsAccountRepositoryImp(
.asDataStateFlow()
}

override fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<DataState<Savings>> {
override fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<DataState<HttpResponse>> {
return dataManagerSavings.createSavingsAccount(savingsPayload)
.asDataStateFlow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package com.mifos.core.domain.useCases
import com.mifos.core.common.utils.DataState
import com.mifos.core.data.repository.SavingsAccountRepository
import com.mifos.core.model.objects.payloads.SavingsPayload
import com.mifos.room.entities.client.Savings
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -23,6 +23,6 @@ class CreateSavingsAccountUseCase(
private val repository: SavingsAccountRepository,
) {

operator fun invoke(savingsPayload: SavingsPayload?): Flow<DataState<Savings?>> =
operator fun invoke(savingsPayload: SavingsPayload?): Flow<DataState<HttpResponse>> =
repository.createSavingsAccount(savingsPayload)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import com.mifos.core.network.BaseApiManager
import com.mifos.core.network.GenericResponse
import com.mifos.room.entities.accounts.savings.SavingsAccountTransactionRequestEntity
import com.mifos.room.entities.accounts.savings.SavingsAccountWithAssociationsEntity
import com.mifos.room.entities.client.Savings
import com.mifos.room.entities.templates.savings.SavingProductsTemplate
import com.mifos.room.entities.templates.savings.SavingsAccountTransactionTemplateEntity
import com.mifos.room.helper.SavingsDaoHelper
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
Expand Down Expand Up @@ -284,7 +284,7 @@ class DataManagerSavings(
val getSavingsAccounts: Flow<List<ProductSavings>>
get() = mBaseApiManager.savingsService.allSavingsAccounts()

fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<Savings> {
fun createSavingsAccount(savingsPayload: SavingsPayload?): Flow<HttpResponse> {
return mBaseApiManager.savingsService.createSavingsAccount(savingsPayload)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import com.mifos.core.network.GenericResponse
import com.mifos.room.basemodel.APIEndPoint
import com.mifos.room.entities.accounts.savings.SavingsAccountTransactionRequestEntity
import com.mifos.room.entities.accounts.savings.SavingsAccountWithAssociationsEntity
import com.mifos.room.entities.client.Savings
import com.mifos.room.entities.templates.savings.SavingProductsTemplate
import com.mifos.room.entities.templates.savings.SavingsAccountTransactionTemplateEntity
import de.jensklingenberg.ktorfit.http.Body
import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.POST
import de.jensklingenberg.ktorfit.http.Path
import de.jensklingenberg.ktorfit.http.Query
import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.flow.Flow

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ interface SavingsAccountService {
fun allSavingsAccounts(): Flow<List<ProductSavings>>

@POST(APIEndPoint.CREATE_SAVINGS_ACCOUNTS)
fun createSavingsAccount(@Body savingsPayload: SavingsPayload?): Flow<Savings>
fun createSavingsAccount(@Body savingsPayload: SavingsPayload?): Flow<HttpResponse>

@GET(APIEndPoint.CREATE_SAVINGS_PRODUCTS + "/template")
fun savingsAccountTemplate(): Flow<SavingProductsTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidclient.feature.savings.generated.resources.feature_savings_continu
import androidclient.feature.savings.generated.resources.feature_savings_create_savings_account
import androidclient.feature.savings.generated.resources.feature_savings_error_not_connected_internet
import androidclient.feature.savings.generated.resources.feature_savings_failed
import androidclient.feature.savings.generated.resources.feature_savings_retry
import androidclient.feature.savings.generated.resources.feature_savings_success
import androidclient.feature.savings.generated.resources.step_charges
import androidclient.feature.savings.generated.resources.step_charges_add
Expand Down Expand Up @@ -169,7 +170,7 @@ private fun SavingsAccountScaffold(
is SavingsAccountState.ScreenState.ShowStatusDialog -> {
MifosStatusDialog(
status = state.screenState.status,
btnText = stringResource(Res.string.feature_savings_continue),
btnText = if (state.screenState.status == ResultStatus.SUCCESS) stringResource(Res.string.feature_savings_continue) else stringResource(Res.string.feature_savings_retry),
onConfirm = { if (state.screenState.status == ResultStatus.SUCCESS) onAction(SavingsAccountAction.Finish) else onAction(SavingsAccountAction.Retry) },
successTitle = stringResource(Res.string.feature_savings_success),
successMessage = state.screenState.msg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import com.mifos.core.common.utils.DataState
import com.mifos.core.common.utils.DateHelper
import com.mifos.core.data.util.Error
import com.mifos.core.data.util.NetworkMonitor
import com.mifos.core.data.util.extractErrorMessage
import com.mifos.core.domain.useCases.CreateSavingsAccountUseCase
import com.mifos.core.domain.useCases.GetClientTemplateUseCase
import com.mifos.core.domain.useCases.GetSavingsProductTemplateUseCase
Expand Down Expand Up @@ -171,14 +173,27 @@ internal class SavingsAccountViewModel(
}
}
is DataState.Success -> {
mutableStateFlow.update {
it.copy(
isOverLayLoadingActive = false,
screenState = SavingsAccountState.ScreenState.ShowStatusDialog(
ResultStatus.SUCCESS,
getString(Res.string.feature_savings_new_savings_account_submitted_success),
),
)
val error = extractErrorMessage(result.data)
if (error == Error.MSG_NOT_FOUND) {
mutableStateFlow.update {
it.copy(
isOverLayLoadingActive = false,
screenState = SavingsAccountState.ScreenState.ShowStatusDialog(
ResultStatus.SUCCESS,
getString(Res.string.feature_savings_new_savings_account_submitted_success),
),
)
}
} else {
mutableStateFlow.update {
it.copy(
screenState = SavingsAccountState.ScreenState.ShowStatusDialog(
ResultStatus.FAILURE,
error,
),
isOverLayLoadingActive = false,
)
}
}
}
is DataState.Error -> {
Expand Down
Loading