Skip to content

Commit d295cab

Browse files
authored
Feat: Migrated Home Module to KMP (#1784)
1 parent a1ca686 commit d295cab

File tree

229 files changed

+3508
-1534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+3508
-1534
lines changed

core/common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ kotlin {
3939
api(libs.kermit.logging)
4040
api(libs.squareup.okio)
4141
api(libs.jb.kotlin.stdlib)
42+
api(libs.kotlinx.datetime)
4243
}
4344

4445
androidMain.dependencies {

core/model/src/commonMain/kotlin/org/mifospay/core/model/utils/DateHelper.kt renamed to core/common/src/commonMain/kotlin/org/mifospay/core/common/DateHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
99
*/
10-
package org.mifospay.core.model.utils
10+
package org.mifospay.core.common
1111

1212
import kotlinx.datetime.Clock
1313
import kotlinx.datetime.DateTimeUnit

core/data/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ kotlin {
2828
commonMain.dependencies {
2929
api(projects.core.common)
3030
api(projects.core.datastore)
31-
api(projects.core.network)
3231
api(projects.core.model)
33-
32+
implementation(projects.core.network)
3433
implementation(projects.core.analytics)
3534
}
3635

core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/AccountMapper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*/
1010
package org.mifospay.core.data.mapper
1111

12-
import org.mifospay.core.model.domain.Account
13-
import org.mifospay.core.model.entity.client.ClientAccounts
12+
import org.mifospay.core.model.account.Account
13+
import org.mifospay.core.network.model.entity.client.ClientAccountsEntity
1414

15-
fun ClientAccounts.toAccount(): List<Account> {
15+
fun ClientAccountsEntity.toAccount(): List<Account> {
1616
return this.savingsAccounts.map {
1717
Account(
1818
name = it.productName,

core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/ClientDetailsMapper.kt

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
*/
1010
package org.mifospay.core.data.mapper
1111

12-
import org.mifospay.core.model.domain.client.Client
13-
import org.mifospay.core.model.entity.Page
14-
import org.mifospay.core.model.entity.client.ClientEntity
12+
import org.mifospay.core.model.client.Client
13+
import org.mifospay.core.model.client.ClientAddress
14+
import org.mifospay.core.model.client.NewClient
15+
import org.mifospay.core.network.model.entity.Page
16+
import org.mifospay.core.network.model.entity.client.Address
17+
import org.mifospay.core.network.model.entity.client.ClientEntity
18+
import org.mifospay.core.network.model.entity.client.NewClientEntity
1519

1620
fun ClientEntity.toModel(): Client {
1721
return Client(
18-
name = this.displayName,
22+
name = this.displayName ?: "",
1923
clientId = this.id.toLong(),
2024
externalId = this.externalId,
2125
mobileNo = this.mobileNo,
@@ -32,3 +36,25 @@ fun Page<ClientEntity>.toModel(): Page<Client> {
3236
pageItems = this.pageItems.map { it.toModel() }.toMutableList(),
3337
)
3438
}
39+
40+
fun NewClient.toEntity(): NewClientEntity {
41+
return NewClientEntity(
42+
firstname = firstname,
43+
lastname = lastname,
44+
externalId = externalId,
45+
mobileNo = mobileNo,
46+
address = address.toEntity(),
47+
savingsProductId = savingsProductId,
48+
)
49+
}
50+
51+
fun ClientAddress.toEntity(): Address {
52+
return Address(
53+
addressLine1 = addressLine1,
54+
addressLine2 = addressLine2,
55+
postalCode = postalCode,
56+
stateProvinceId = stateProvinceId,
57+
countryId = countryId,
58+
addressTypeId = addressTypeId,
59+
)
60+
}

core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/CurrencyMapper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*/
1010
package org.mifospay.core.data.mapper
1111

12-
import org.mifospay.core.model.entity.accounts.savings.Currency
13-
import org.mifospay.core.model.domain.Currency as DomainCurrency
12+
import org.mifospay.core.network.model.entity.accounts.savings.CurrencyEntity
13+
import org.mifospay.core.model.savingsaccount.Currency as DomainCurrency
1414

15-
fun Currency.toModel(): DomainCurrency {
15+
fun CurrencyEntity.toModel(): DomainCurrency {
1616
return DomainCurrency(
1717
code = this.code,
1818
displayLabel = this.displayLabel,

core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/SearchedEntitiesMapper.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
*/
1010
package org.mifospay.core.data.mapper
1111

12-
import org.mifospay.core.model.domain.SearchResult
13-
import org.mifospay.core.model.entity.SearchedEntity
12+
import org.mifospay.core.model.search.SearchResult
13+
import org.mifospay.core.network.model.entity.SearchedEntity
1414

15-
fun SearchedEntity.toSearchResult(): SearchResult {
15+
fun SearchedEntity.toModel(): SearchResult {
1616
return SearchResult(
17-
resultId = this.entityId,
18-
resultName = this.entityName,
19-
resultType = this.entityType,
17+
entityId = entityId,
18+
entityAccountNo = entityAccountNo,
19+
entityName = entityName,
20+
entityType = entityType,
21+
parentId = parentId,
22+
parentName = parentName,
2023
)
2124
}
2225

23-
fun List<SearchedEntity>.toSearchResult(): List<SearchResult> = map { it.toSearchResult() }
26+
fun List<SearchedEntity>.toSearchResult(): List<SearchResult> = map { it.toModel() }
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2024 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
9+
*/
10+
package org.mifospay.core.data.mapper
11+
12+
import org.mifospay.core.model.savingsaccount.DepositType
13+
import org.mifospay.core.model.savingsaccount.SavingAccount
14+
import org.mifospay.core.model.savingsaccount.Status
15+
import org.mifospay.core.model.savingsaccount.TransferDetail
16+
import org.mifospay.core.network.model.entity.accounts.savings.SavingAccountEntity
17+
import org.mifospay.core.network.model.entity.accounts.savings.StatusEntity
18+
import org.mifospay.core.network.model.entity.accounts.savings.TransferDetailEntity
19+
import org.mifospay.core.network.model.entity.client.DepositTypeEntity
20+
21+
fun TransferDetailEntity.toModel(): TransferDetail {
22+
return TransferDetail(
23+
id = id,
24+
fromClient = fromClient.toModel(),
25+
fromAccount = fromAccount.toModel(),
26+
toClient = toClient.toModel(),
27+
toAccount = toAccount.toModel(),
28+
)
29+
}
30+
31+
fun SavingAccountEntity.toModel(): SavingAccount {
32+
return SavingAccount(
33+
id = id,
34+
accountNo = accountNo,
35+
productName = productName,
36+
productId = productId,
37+
overdraftLimit = overdraftLimit,
38+
minRequiredBalance = minRequiredBalance,
39+
accountBalance = accountBalance,
40+
totalDeposits = totalDeposits,
41+
savingsProductName = savingsProductName,
42+
clientName = clientName,
43+
savingsProductId = savingsProductId,
44+
nominalAnnualInterestRate = nominalAnnualInterestRate,
45+
status = status?.toModel(),
46+
currency = currency.toModel(),
47+
depositType = depositType?.toModel(),
48+
isRecurring = this.isRecurring(),
49+
)
50+
}
51+
52+
fun StatusEntity.toModel(): Status {
53+
return Status(
54+
id = id,
55+
code = code,
56+
value = value,
57+
submittedAndPendingApproval = submittedAndPendingApproval,
58+
approved = approved,
59+
rejected = rejected,
60+
withdrawnByApplicant = withdrawnByApplicant,
61+
active = active,
62+
closed = closed,
63+
prematureClosed = prematureClosed,
64+
transferInProgress = transferInProgress,
65+
transferOnHold = transferOnHold,
66+
matured = matured,
67+
)
68+
}
69+
70+
fun DepositTypeEntity.toModel(): DepositType {
71+
return DepositType(
72+
id = id,
73+
code = code,
74+
value = value,
75+
)
76+
}

core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/TransactionMapper.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
*/
1010
package org.mifospay.core.data.mapper
1111

12-
import org.mifospay.core.model.domain.Transaction
13-
import org.mifospay.core.model.domain.TransactionType
14-
import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity
15-
import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity
16-
import org.mifospay.core.model.utils.DateHelper
12+
import org.mifospay.core.common.DateHelper
13+
import org.mifospay.core.model.savingsaccount.Transaction
14+
import org.mifospay.core.model.savingsaccount.TransactionType
15+
import org.mifospay.core.network.model.entity.accounts.savings.SavingsWithAssociationsEntity
16+
import org.mifospay.core.network.model.entity.accounts.savings.TransactionsEntity
1717

1818
fun SavingsWithAssociationsEntity.toTransactionList(): List<Transaction> {
1919
return this.transactions.map { it.toModel() }
@@ -32,5 +32,8 @@ fun TransactionsEntity.toModel(): Transaction {
3232
else -> TransactionType.OTHER
3333
},
3434
transferId = this.originalTransactionId ?: 0,
35+
clientId = 0,
36+
accountId = this.accountId?.toLong() ?: 0L,
37+
transferDetail = null,
3538
)
3639
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2024 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
9+
*/
10+
package org.mifospay.core.data.mapper
11+
12+
import org.mifospay.core.model.user.NewUser
13+
import org.mifospay.core.model.user.RoleInfo
14+
import org.mifospay.core.model.user.UserInfo
15+
import org.mifospay.core.network.model.entity.Role
16+
import org.mifospay.core.network.model.entity.user.NewUserEntity
17+
import org.mifospay.core.network.model.entity.user.User
18+
19+
private const val OFFICE_ID = 1
20+
private const val MOBILE_WALLET_ROLE_ID = 2
21+
private const val SUPER_USER_ROLE_ID = 1
22+
23+
val NEW_USER_ROLE_IDS: ArrayList<Int> = arrayListOf(MOBILE_WALLET_ROLE_ID, SUPER_USER_ROLE_ID)
24+
25+
fun NewUser.toEntity(): NewUserEntity {
26+
return NewUserEntity(
27+
username = username,
28+
firstname = firstname,
29+
lastname = lastname,
30+
email = email,
31+
password = password,
32+
officeId = OFFICE_ID,
33+
roles = NEW_USER_ROLE_IDS,
34+
sendPasswordToEmail = false,
35+
isSelfServiceUser = true,
36+
repeatPassword = password,
37+
)
38+
}
39+
40+
fun User.toUserInfo() = UserInfo(
41+
username = username,
42+
userId = userId,
43+
base64EncodedAuthenticationKey = base64EncodedAuthenticationKey,
44+
authenticated = authenticated,
45+
officeId = officeId,
46+
officeName = officeName,
47+
roles = roles.map { it.toRoleInfo() },
48+
permissions = permissions,
49+
clients = clients,
50+
shouldRenewPassword = shouldRenewPassword,
51+
isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired,
52+
)
53+
54+
fun Role.toRoleInfo() = RoleInfo(
55+
id = id ?: "",
56+
name = name ?: "",
57+
description = description ?: "",
58+
disabled = disabled,
59+
)

0 commit comments

Comments
 (0)