-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: [:core:datastore] - Migrated to KMP (#1769)
- Loading branch information
Showing
18 changed files
with
503 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
core/datastore-proto/src/androidMain/proto/org.mifospay.core.data/user_preferences.proto
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...astore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/ClientPreferences.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,24 @@ | ||
package org.mifospay.core.datastore.proto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ClientPreferences( | ||
val name: String, | ||
val image: String, | ||
val externalId: String, | ||
val clientId: Long, | ||
val displayName: String, | ||
val mobileNo: String, | ||
) { | ||
companion object { | ||
val DEFAULT = ClientPreferences( | ||
name = "", | ||
image = "", | ||
externalId = "", | ||
clientId = 0, | ||
displayName = "", | ||
mobileNo = "", | ||
) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...atastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/RolePreferences.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,20 @@ | ||
package org.mifospay.core.datastore.proto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RolePreferences( | ||
val id: String, | ||
val name: String, | ||
val description: String, | ||
val disabled: Boolean | ||
) { | ||
companion object { | ||
val DEFAULT = RolePreferences( | ||
id = "", | ||
name = "", | ||
description = "", | ||
disabled = false | ||
) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserInfoPreferences.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,34 @@ | ||
package org.mifospay.core.datastore.proto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserInfoPreferences( | ||
val username: String, | ||
val userId: Int, | ||
val base64EncodedAuthenticationKey: String, | ||
val authenticated: Boolean, | ||
val officeId: Int, | ||
val officeName: String, | ||
val roles: List<RolePreferences>, | ||
val permissions: List<String>, | ||
val clients: List<Long>, | ||
val shouldRenewPassword: Boolean, | ||
val isTwoFactorAuthenticationRequired: Boolean | ||
) { | ||
companion object { | ||
val DEFAULT = UserInfoPreferences( | ||
username = "", | ||
userId = 0, | ||
base64EncodedAuthenticationKey = "", | ||
authenticated = false, | ||
officeId = 0, | ||
officeName = "", | ||
roles = emptyList(), | ||
permissions = emptyList(), | ||
clients = emptyList(), | ||
shouldRenewPassword = false, | ||
isTwoFactorAuthenticationRequired = false | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...atastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserPreferences.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,36 @@ | ||
package org.mifospay.core.datastore.proto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserPreferences( | ||
val token: String, | ||
val name: String, | ||
val username: String, | ||
val email: String, | ||
val mobileNo: String, | ||
val userId: Int, | ||
val clientId: Int, | ||
val clientVpa: String, | ||
val accountId: Int, | ||
val firebaseRegId: String, | ||
val client: ClientPreferences, | ||
val user: UserInfoPreferences, | ||
) { | ||
companion object { | ||
val DEFAULT = UserPreferences( | ||
token = "", | ||
name = "", | ||
username = "", | ||
email = "", | ||
mobileNo = "", | ||
userId = 0, | ||
clientId = 0, | ||
clientVpa = "", | ||
accountId = 0, | ||
firebaseRegId = "", | ||
client = ClientPreferences.DEFAULT, | ||
user = UserInfoPreferences.DEFAULT, | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ore-proto/src/commonMain/kotlin/proto/org/mifospay/core/datastore/proto/client_info.proto
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,13 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "org.mifospay.core.datastore.proto"; | ||
option java_multiple_files = true; | ||
|
||
message Client { | ||
string name = 1; | ||
string image = 2; | ||
string external_id = 3; | ||
int64 client_id = 4; | ||
string display_name = 5; | ||
string mobile_no = 6; | ||
} |
11 changes: 11 additions & 0 deletions
11
...store-proto/src/commonMain/kotlin/proto/org/mifospay/core/datastore/proto/role_info.proto
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,11 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "org.mifospay.core.datastore.proto"; | ||
option java_multiple_files = true; | ||
|
||
message Role { | ||
string id = 1; | ||
string name = 2; | ||
string description = 3; | ||
bool disabled = 4; | ||
} |
20 changes: 20 additions & 0 deletions
20
...store-proto/src/commonMain/kotlin/proto/org/mifospay/core/datastore/proto/user_info.proto
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,20 @@ | ||
syntax = "proto3"; | ||
|
||
import "proto/org/mifospay/core/datastore/proto/role_info.proto"; | ||
|
||
option java_package = "org.mifospay.core.datastore.proto"; | ||
option java_multiple_files = true; | ||
|
||
message User { | ||
string username = 1; | ||
int64 userId = 2; | ||
string base64EncodedAuthenticationKey = 3; | ||
bool authenticated = 4; | ||
int32 officeId = 5; | ||
string officeName = 6; | ||
repeated Role roles = 7; | ||
repeated string permissions = 8; | ||
repeated int64 clients = 9; | ||
bool shouldRenewPassword = 10; | ||
bool isTwoFactorAuthenticationRequired = 11; | ||
} |
22 changes: 22 additions & 0 deletions
22
...proto/src/commonMain/kotlin/proto/org/mifospay/core/datastore/proto/user_preference.proto
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,22 @@ | ||
syntax = "proto3"; | ||
|
||
import "org.mifospay.core.datastore.proto.client_info.proto"; | ||
import "org.mifospay.core.datastore.proto.user_info.proto"; | ||
|
||
option java_package = "org.mifospay.core.datastore.proto"; | ||
option java_multiple_files = true; | ||
|
||
message UserPreferences { | ||
string token = 1; | ||
string name = 2; | ||
string username = 3; | ||
string email = 4; | ||
string mobile_no = 5; | ||
int32 user_id = 6; | ||
int32 client_id = 7; | ||
string client_vpa = 8; | ||
int32 account_id = 9; | ||
string firebase_reg_id = 10; | ||
Client client = 11; | ||
User user = 12; | ||
} |
116 changes: 116 additions & 0 deletions
116
core/datastore/src/commonMain/kotlin/org/mifospay/core/datastore/PreferencesMapper.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,116 @@ | ||
package org.mifospay.core.datastore | ||
|
||
import org.mifospay.core.datastore.proto.ClientPreferences | ||
import org.mifospay.core.datastore.proto.RolePreferences | ||
import org.mifospay.core.datastore.proto.UserInfoPreferences | ||
import org.mifospay.core.datastore.proto.UserPreferences | ||
import org.mifospay.core.model.ClientInfo | ||
import org.mifospay.core.model.RoleInfo | ||
import org.mifospay.core.model.UserData | ||
import org.mifospay.core.model.UserInfo | ||
|
||
fun ClientPreferences.toClientInfo(): ClientInfo { | ||
return ClientInfo( | ||
name = name, | ||
image = image, | ||
externalId = externalId, | ||
clientId = clientId, | ||
displayName = displayName, | ||
mobileNo = mobileNo, | ||
) | ||
} | ||
|
||
fun ClientInfo.toClientPreferences(): ClientPreferences { | ||
return ClientPreferences( | ||
name = name, | ||
image = image, | ||
externalId = externalId, | ||
clientId = clientId, | ||
displayName = displayName, | ||
mobileNo = mobileNo, | ||
) | ||
} | ||
|
||
fun RolePreferences.toRoleInfo(): RoleInfo { | ||
return RoleInfo( | ||
id = id, | ||
name = name, | ||
description = description, | ||
disabled = disabled, | ||
) | ||
} | ||
|
||
fun RoleInfo.toRolePreferences(): RolePreferences { | ||
return RolePreferences( | ||
id = id, | ||
name = name, | ||
description = description, | ||
disabled = disabled, | ||
) | ||
} | ||
|
||
fun UserInfoPreferences.toUserInfo(): UserInfo { | ||
return UserInfo( | ||
username = username, | ||
userId = userId, | ||
base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, | ||
authenticated = authenticated, | ||
officeId = officeId, | ||
officeName = officeName, | ||
roles = roles.map { it.toRoleInfo() }, | ||
permissions = permissions, | ||
clients = clients, | ||
shouldRenewPassword = shouldRenewPassword, | ||
isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, | ||
) | ||
} | ||
|
||
fun UserInfo.toUserInfoPreferences(): UserInfoPreferences { | ||
return UserInfoPreferences( | ||
username = username, | ||
userId = userId, | ||
base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, | ||
authenticated = authenticated, | ||
officeId = officeId, | ||
officeName = officeName, | ||
roles = roles.map { it.toRolePreferences() }, | ||
permissions = permissions, | ||
clients = clients, | ||
shouldRenewPassword = shouldRenewPassword, | ||
isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, | ||
) | ||
} | ||
|
||
fun UserPreferences.toUserData(): UserData { | ||
return UserData( | ||
token = token, | ||
name = name, | ||
username = username, | ||
email = email, | ||
mobileNo = mobileNo, | ||
userId = userId, | ||
clientId = clientId, | ||
clientVpa = clientVpa, | ||
accountId = accountId, | ||
firebaseRegId = firebaseRegId, | ||
client = client.toClientInfo(), | ||
user = user.toUserInfo(), | ||
) | ||
} | ||
|
||
fun UserData.toUserPreferences(): UserPreferences { | ||
return UserPreferences( | ||
token = token, | ||
name = name, | ||
username = username, | ||
email = email, | ||
mobileNo = mobileNo, | ||
userId = userId, | ||
clientId = clientId, | ||
clientVpa = clientVpa, | ||
accountId = accountId, | ||
firebaseRegId = firebaseRegId, | ||
client = client.toClientPreferences(), | ||
user = user.toUserInfoPreferences(), | ||
) | ||
} |
Oops, something went wrong.