Skip to content

Commit

Permalink
DAO migration
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Jan 20, 2025
1 parent 5a80565 commit a2a64ee
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 2 deletions.
45 changes: 45 additions & 0 deletions core/database/schemas/com.mifos.room.db.MifosDatabase/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "52a9a8b64b78975c74e557a9c0411c25",
"entities": [
{
"tableName": "ColumnValue",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `value` TEXT, `score` INTEGER, `registeredTableName` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER"
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT"
},
{
"fieldPath": "score",
"columnName": "score",
"affinity": "INTEGER"
},
{
"fieldPath": "registeredTableName",
"columnName": "registeredTableName",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '52a9a8b64b78975c74e557a9c0411c25')"
]
}
}
52 changes: 52 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/CenterDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.mifos.room.entities.accounts.CenterAccounts
import com.mifos.room.entities.center.CenterPayload
import com.mifos.room.entities.group.Center
import com.mifos.room.entities.group.Group

@Dao
interface CenterDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCenters(centers: List<Center>)

@Query("SELECT * FROM center")
suspend fun getAllCenters(): List<Center>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveCenter(center: Center)

@Query("SELECT * FROM GroupTable WHERE centerId = :centerId")
suspend fun getCenterAssociatedGroups(centerId: Int): List<Group>

@Delete
suspend fun deleteCenterPayload(centerPayload: CenterPayload)

@Query("SELECT * FROM CenterPayload")
suspend fun getAllCenterPayloads(): List<CenterPayload>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCenterPayload(centerPayload: CenterPayload)

@Update
suspend fun updateCenterPayload(centerPayload: CenterPayload)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveCenterAccounts(accounts: List<CenterAccounts>)
}
27 changes: 27 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/ChargeDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mifos.room.entities.client.Charges
import kotlinx.coroutines.flow.Flow

@Dao
interface ChargeDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveClientCharges(charges: List<Charges>)

@Query("SELECT * FROM Charges WHERE clientId = :clientId")
fun readClientCharges(clientId: Int): Flow<List<Charges>>
}
41 changes: 41 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/ClientDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.mifos.room.entities.client.Client
import kotlinx.coroutines.flow.Flow

@Dao
interface ClientDao {

@Insert
fun insertClient(client: Client)

@Insert
fun insertClients(clients: List<Client>)

@Query("SELECT * FROM Client WHERE id = :clientId")
fun getClientById(clientId: Int): LiveData<Client>

@Query("SELECT * FROM Client")
fun getAllClients(): Flow<List<Client>>

@Update
fun updateClient(client: Client)

@Delete
fun deleteClient(client: Client)
}
12 changes: 12 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/DataTableDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

interface DataTableDao
34 changes: 34 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/GroupsDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mifos.room.entities.group.Group
import com.mifos.room.entities.organisation.Staff
import kotlinx.coroutines.flow.Flow

/**
* Created by Pronay Sarker on 20/01/2025 (4:54 PM)
*/
@Dao
interface GroupsDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveGroup(group: Group)

@Query("Select * from GroupTable")
suspend fun readAllGroups(): Flow<List<Group>>

@Query("SELECT * FROM Staff WHERE officeId = :officeId")
fun readAllStaffOffices(officeId: Int): Flow<List<Staff>>
}
43 changes: 43 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/LoanDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate

@Dao
interface LoanDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertLoan(loanWithAssociations: LoanWithAssociations)

@Query("SELECT * FROM LoanWithAssociations WHERE id = :loanId")
suspend fun getLoanById(loanId: Int): LoanWithAssociations?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertLoanRepaymentTransaction(request: LoanRepaymentRequest)

@Query("SELECT * FROM LoanRepaymentTemplate WHERE loanId = :loanId ORDER BY timeStamp ASC")
suspend fun getLoanRepaymentsByLoanId(loanId: Int): List<LoanRepaymentRequest>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertLoanRepaymentTemplate(template: LoanRepaymentTemplate)

@Query("SELECT * FROM LoanRepaymentTemplate WHERE loanId = :loanId")
suspend fun getLoanRepaymentTemplate(loanId: Int): LoanRepaymentTemplate?

@Query("DELETE FROM LoanRepaymentTemplate WHERE loanId = :loanId")
suspend fun deleteLoanRepaymentByLoanId(loanId: Int)
}
15 changes: 15 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/NoteDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

/**
* Created by Pronay Sarker on 20/01/2025 (4:54 PM)
*/
interface NoteDao
27 changes: 27 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/OfficesDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mifos.room.entities.organisation.Office
import kotlinx.coroutines.flow.Flow

@Dao
interface OfficesDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAllOffices(offices: List<Office>)

@Query("SELECT * FROM Office")
fun getAllOffices(): Flow<List<Office>>
}
50 changes: 50 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/SavingsDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import com.mifos.room.entities.accounts.savings.SavingsAccountTransactionRequest
import com.mifos.room.entities.accounts.savings.SavingsAccountWithAssociations
import com.mifos.room.entities.accounts.savings.Transaction
import com.mifos.room.entities.templates.savings.SavingsAccountTransactionTemplate

@Dao
interface SavingsDao {

@Insert
suspend fun insertSavingsAccount(account: SavingsAccountWithAssociations)

@Query("SELECT * FROM SavingsAccountWithAssociations WHERE id = :savingsAccountId")
suspend fun getSavingsAccount(savingsAccountId: Int): SavingsAccountWithAssociations

@Insert
suspend fun insertTransaction(transaction: Transaction)

@Query("SELECT * FROM TransactionTable WHERE savingsAccountId = :savingsAccountId")
suspend fun getTransactions(savingsAccountId: Int): List<Transaction>

@Insert
suspend fun insertTransactionTemplate(template: SavingsAccountTransactionTemplate)

@Query("SELECT * FROM SavingsAccountTransactionTemplate WHERE accountId = :savingsAccountId")
suspend fun getTransactionTemplate(savingsAccountId: Int): SavingsAccountTransactionTemplate

@Insert
suspend fun insertTransactionRequest(request: SavingsAccountTransactionRequest)

@Query("SELECT * FROM SavingsAccountTransactionRequest WHERE savingAccountId = :savingsAccountId")
suspend fun getTransactionRequest(savingsAccountId: Int): SavingsAccountTransactionRequest

@Delete
suspend fun deleteTransactionRequest(request: SavingsAccountTransactionRequest)
}
30 changes: 30 additions & 0 deletions core/database/src/main/java/com/mifos/room/dao/StaffDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mifos.room.entities.organisation.Staff
import kotlinx.coroutines.flow.Flow

/**
* Created by Pronay Sarker on 20/01/2025 (11:50 AM)
*/
@Dao
interface StaffDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAllStaffs(staffs: List<Staff>)

@Query("SELECT * FROM Staff WHERE officeId = :officeId")
fun readAllStaffOffices(officeId: Int): Flow<List<Staff>>
}
Loading

0 comments on commit a2a64ee

Please sign in to comment.