-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrated savings service from retrofit to ktor (#1758)
* getSavingsAccounts in SavingsAccountService migrated to ktor * migrated savings account service to ktor
- Loading branch information
1 parent
7089ebc
commit 5059e62
Showing
8 changed files
with
135 additions
and
125 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
49 changes: 47 additions & 2 deletions
49
core/network/src/main/kotlin/org/mifospay/core/network/services/KtorSavingsAccountService.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 |
---|---|---|
@@ -1,24 +1,69 @@ | ||
package org.mifospay.core.network.services | ||
|
||
import com.mifospay.core.model.entity.Page | ||
import com.mifospay.core.model.entity.accounts.savings.SavingAccount | ||
import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations | ||
import com.mifospay.core.model.entity.accounts.savings.Transactions | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.contentType | ||
import jakarta.inject.Inject | ||
import org.mifospay.core.network.ApiEndPoints | ||
import org.mifospay.core.network.BaseURL | ||
import org.mifospay.core.network.GenericResponse | ||
|
||
class KtorSavingsAccountService @Inject constructor( | ||
private val client: HttpClient | ||
private val client: HttpClient, | ||
) { | ||
suspend fun getSavingsWithAssociations( | ||
accountId: Long, | ||
associationType: String | ||
associationType: String, | ||
): SavingsWithAssociations { | ||
return client.get("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}/$accountId") { | ||
url { | ||
parameters.append("associations", associationType) | ||
} | ||
}.body() | ||
} | ||
|
||
suspend fun getSavingsAccounts(limit: Int): Page<SavingsWithAssociations> { | ||
return client.get("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}") { | ||
url { | ||
parameters.append("limit", limit.toString()) | ||
} | ||
}.body() | ||
} | ||
|
||
suspend fun createSavingsAccount(savingAccount: SavingAccount): GenericResponse { | ||
return client.post("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}") { | ||
contentType(ContentType.Application.Json) | ||
setBody(savingAccount) | ||
}.body() | ||
} | ||
|
||
suspend fun blockUnblockAccount(accountId: Long, command: String?): GenericResponse { | ||
return client.post("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}/$accountId") { | ||
url { | ||
parameters.append("command", command ?: "") | ||
} | ||
}.body() | ||
} | ||
|
||
suspend fun getSavingAccountTransaction(accountId: Long, transactionId: Long): Transactions { | ||
return client.get("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}/$accountId/${ApiEndPoints.TRANSACTIONS}/$transactionId") | ||
.body() | ||
} | ||
|
||
suspend fun payViaMobile(accountId: Long): Transactions { | ||
return client.post("${BaseURL().selfServiceUrl}${ApiEndPoints.SAVINGS_ACCOUNTS}/$accountId/${ApiEndPoints.TRANSACTIONS}") { | ||
url { | ||
parameters.append("command", "deposit") | ||
} | ||
}.body() | ||
} | ||
|
||
} |
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