Skip to content

Commit

Permalink
feat: realm implementation to get client list
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Feb 19, 2024
1 parent 4822876 commit 9a05f5a
Show file tree
Hide file tree
Showing 30 changed files with 569 additions and 309 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ plugins {
id("com.android.library") version "8.1.2" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.5.21" apply false
id("androidx.navigation.safeargs") version "2.6.0" apply false
id("io.realm.kotlin") version "1.11.0" apply false
}
35 changes: 2 additions & 33 deletions core/data/src/main/java/com/mifos/core/data/model/client/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,28 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import com.mifos.core.data.model.database.MifosDatabase
import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.ForeignKey
import com.raizlabs.android.dbflow.annotation.ModelContainer
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import kotlinx.parcelize.Parcelize

/**
* Created by ishankhanna on 08/02/14.
*/
@Parcelize
@Table(database = MifosDatabase::class, useBooleanGetterSetters = false)
@ModelContainer
data class Client(
@PrimaryKey

var id: Int = 0,

@Column
@Transient
var groupId: Int? = 0,

@Column
var accountNo: String? = null,

var clientId: Int? = null,

@Column
@ForeignKey(saveForeignKeyModel = true)
var status: Status? = null,

@Column
@Transient
var sync: Boolean = false,

@Column
var active: Boolean = false,

@Column
@ForeignKey(saveForeignKeyModel = true)
var clientDate: ClientDate? = null,

var activationDate: List<Int?> = ArrayList(),
Expand All @@ -56,44 +37,32 @@ data class Client(

var mobileNo: String? = null,

@Column
var firstname: String? = null,

@Column
var middlename: String? = null,

@Column
var lastname: String? = null,

@Column
var displayName: String? = null,

@Column
var officeId: Int = 0,

@Column
var officeName: String? = null,

@Column
var staffId: Int = 0,

@Column
var staffName: String? = null,

var timeline: Timeline? = null,

@Column
var fullname: String? = null,

@Column
var imageId: Int = 0,

@Column
var imagePresent: Boolean = false,

@Column
var externalId: String? = null
) : MifosBaseModel(), Parcelable {
) : Parcelable {

/**
* This method is returning the comma separated names of all the client's group
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import com.mifos.core.data.model.database.MifosDatabase
import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.ModelContainer
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import kotlinx.parcelize.Parcelize

/**
* Created by Rajan Maurya on 04/07/16.
*/
@Parcelize
@Table(database = MifosDatabase::class)
@ModelContainer
data class ClientDate(
@PrimaryKey

var clientId: Long = 0,

@PrimaryKey
var chargeId: Long = 0,

@Column
var day: Int = 0,

@Column
var month: Int = 0,

@Column
var year: Int = 0
) : MifosBaseModel(), Parcelable
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,47 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import com.mifos.core.data.model.database.MifosDatabase
import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.ForeignKey
import com.raizlabs.android.dbflow.annotation.ModelContainer
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import kotlinx.parcelize.Parcelize

/**
* This is the Groups Model Table
* Created by ishankhanna on 28/06/14.
*/
@Parcelize
@Table(database = MifosDatabase::class, useBooleanGetterSetters = false)
@ModelContainer
data class Group(
@PrimaryKey
var id: Int? = null,

@Column
var accountNo: String? = null,

@Column
@Transient
var sync: Boolean = false,

@Column
var name: String? = null,

var status: Status? = null,

@Column
var active: Boolean? = null,

@Column
@ForeignKey(saveForeignKeyModel = true)
@Transient
var groupDate: GroupDate? = null,

var activationDate: List<Int> = ArrayList(),

@Column
var officeId: Int? = null,

@Column
var officeName: String? = null,

@Column
var centerId: Int? = 0,

@Column
var centerName: String? = null,

@Column
var staffId: Int? = null,

@Column
var staffName: String? = null,

@Column
var hierarchy: String? = null,

@Column
var groupLevel: Int = 0,

var timeline: Timeline? = null,

var externalId: String? = null
) : MifosBaseModel(), Parcelable
) : Parcelable
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import com.mifos.core.data.model.database.MifosDatabase
import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.ModelContainer
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import kotlinx.parcelize.Parcelize

/**
* Created by Rajan Maurya on 18/09/16.
*/
@Parcelize
@Table(database = MifosDatabase::class)
@ModelContainer
data class GroupDate(
@PrimaryKey

var groupId: Long = 0,

@PrimaryKey
var chargeId: Long = 0,

@Column
var day: Int = 0,

@Column
var month: Int = 0,

@Column
var year: Int = 0
) : MifosBaseModel(), Parcelable
) : Parcelable
12 changes: 2 additions & 10 deletions core/data/src/main/java/com/mifos/core/data/model/client/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import com.mifos.core.data.model.database.MifosDatabase
import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import kotlinx.parcelize.Parcelize

/**
Expand All @@ -18,17 +13,14 @@ import kotlinx.parcelize.Parcelize
* Created by ishankhanna on 09/02/14.
*/
@Parcelize
@Table(database = MifosDatabase::class)
data class Status(
@PrimaryKey

var id: Int = 0,

@Column
var code: String? = null,

@Column
var value: String? = null,
) : MifosBaseModel(), Parcelable {
) : Parcelable {


companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
package com.mifos.core.data.model.client

import android.os.Parcelable
import com.mifos.core.data.model.database.MifosBaseModel
import kotlinx.parcelize.Parcelize

/**
* Created by ishankhanna on 09/02/14.
*/
@Parcelize
class Timeline(
data class Timeline(
var submittedOnDate: MutableList<Int> = ArrayList(),

var submittedByUsername: String? = null,
Expand All @@ -36,4 +35,4 @@ class Timeline(
var closedByFirstname: String? = null,

var closedByLastname: String? = null
) : MifosBaseModel(), Parcelable
) : Parcelable

This file was deleted.

This file was deleted.

12 changes: 10 additions & 2 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
id("io.realm.kotlin")
}

android {
Expand All @@ -29,8 +30,11 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
}
}
}

Expand Down Expand Up @@ -66,4 +70,8 @@ dependencies {

// sdk client
implementation("com.github.openMF:fineract-client:2.0.3")

// Mongo Realm
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("io.realm.kotlin:library-base:1.11.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mifos.core.database

import com.mifos.core.common.utils.Page
import com.mifos.core.model.ClientDb
import io.realm.kotlin.Realm
import io.realm.kotlin.ext.query
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class DatabaseClientQuery @Inject constructor(private val realm: Realm) {

fun getClientListFromDb(): Flow<Page<ClientDb>> {
return realm.query<ClientDb>().asFlow()
.map { Page(totalFilteredRecords = it.list.size, pageItems = it.list) }
}

}
Loading

0 comments on commit 9a05f5a

Please sign in to comment.