Skip to content

Commit

Permalink
Feat: [:core:datastore] - Migrated to KMP (openMF#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Sep 26, 2024
1 parent d6623f8 commit f03a2a0
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 54 deletions.
13 changes: 0 additions & 13 deletions core/datastore-proto/src/androidMain/AndroidManifest.xml

This file was deleted.

This file was deleted.

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 = "",
)
}
}
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
)
}
}
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
)
}
}
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,
)
}
}
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;
}
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;
}
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;
}
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;
}
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(),
)
}
Loading

0 comments on commit f03a2a0

Please sign in to comment.