Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
[IVY-2863] Tag DAOs & POJOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwa-Raghavendra committed Jan 29, 2024
1 parent 6169c96 commit 32f34ac
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.ivy.data.db.dao.read.LoanDao
import com.ivy.data.db.dao.read.LoanRecordDao
import com.ivy.data.db.dao.read.PlannedPaymentRuleDao
import com.ivy.data.db.dao.read.SettingsDao
import com.ivy.data.db.dao.read.TagDao
import com.ivy.data.db.dao.read.TagTransactionDao
import com.ivy.data.db.dao.read.TransactionDao
import com.ivy.data.db.dao.read.UserDao
import com.ivy.data.db.dao.write.WriteAccountDao
Expand All @@ -21,6 +23,8 @@ import com.ivy.data.db.dao.write.WriteLoanDao
import com.ivy.data.db.dao.write.WriteLoanRecordDao
import com.ivy.data.db.dao.write.WritePlannedPaymentRuleDao
import com.ivy.data.db.dao.write.WriteSettingsDao
import com.ivy.data.db.dao.write.WriteTagDao
import com.ivy.data.db.dao.write.WriteTagTransactionDao
import com.ivy.data.db.dao.write.WriteTransactionDao
import com.ivy.data.db.entity.AccountEntity
import com.ivy.data.db.entity.BudgetEntity
Expand Down Expand Up @@ -85,6 +89,8 @@ abstract class IvyRoomDatabase : RoomDatabase() {
abstract val exchangeRatesDao: ExchangeRatesDao
abstract val loanDao: LoanDao
abstract val loanRecordDao: LoanRecordDao
abstract val tagDao : TagDao
abstract val tagTransactionDao : TagTransactionDao

abstract val writeAccountDao: WriteAccountDao
abstract val writeTransactionDao: WriteTransactionDao
Expand All @@ -95,6 +101,8 @@ abstract class IvyRoomDatabase : RoomDatabase() {
abstract val writeExchangeRatesDao: WriteExchangeRatesDao
abstract val writeLoanDao: WriteLoanDao
abstract val writeLoanRecordDao: WriteLoanRecordDao
abstract val writeTagDao : WriteTagDao
abstract val writeTagTransactionDao : WriteTagTransactionDao

companion object {
const val DB_NAME = "ivywallet.db"
Expand Down Expand Up @@ -146,6 +154,8 @@ abstract class IvyRoomDatabase : RoomDatabase() {
writeLoanDao.deleteAll()
writeLoanRecordDao.deleteAll()
writeExchangeRatesDao.deleteALl()
writeTagDao.deleteAll()
writeTransactionDao.deleteAll()
}

@DeleteColumn(tableName = "accounts", columnName = "seAccountId")
Expand Down
22 changes: 22 additions & 0 deletions ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ivy.data.db.dao.read

import androidx.room.*
import com.ivy.data.db.entity.TagEntity
import java.util.*

@Dao
interface TagDao {
@Query("SELECT * FROM tags ORDER BY orderNum ASC")
suspend fun findAll(): List<TagEntity>

@Query("SELECT * FROM tags WHERE id = :id")
suspend fun findById(id: UUID): TagEntity?

@Query("SELECT * FROM tags JOIN tags_transaction ON tags.id = tags_transaction.tagId WHERE associatedId IN (:ids) GROUP BY tags.id")
@RewriteQueriesToDropUnusedColumns
suspend fun findTagsByAssociatedIds(ids: List<UUID>): Map<@MapColumn(columnName = "id") UUID, List<TagEntity>>

@Query("SELECT * FROM tags JOIN tags_transaction ON tags.id = tags_transaction.tagId WHERE associatedId = :id")
@RewriteQueriesToDropUnusedColumns
suspend fun findTagsByAssociatedId(id: UUID): List<TagEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ivy.data.db.dao.read

import androidx.room.Dao
import androidx.room.Query
import com.ivy.data.db.entity.TagTransactionEntity
import java.util.UUID

@Dao
interface TagTransactionDao {
@Query("SELECT * FROM tags_transaction")
suspend fun findAll(): List<TagTransactionEntity>

@Query("SELECT * FROM tags_transaction WHERE tagId = :id")
suspend fun findById(id: UUID): TagTransactionEntity?

@Query("SELECT * FROM tags_transaction WHERE associatedId = :associatedId")
suspend fun findByAssociatedId(associatedId: UUID): TagTransactionEntity?
}
23 changes: 23 additions & 0 deletions ivy-data/src/main/java/com/ivy/data/db/dao/write/WriteTagDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ivy.data.db.dao.write

import androidx.room.*
import com.ivy.data.db.entity.TagEntity
import java.util.*

@Dao
interface WriteTagDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(value: TagEntity)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(value: List<TagEntity>)

@Update
suspend fun update(value: TagEntity)

@Query("DELETE FROM tags WHERE id = :id")
suspend fun deleteById(id: UUID)

@Query("DELETE FROM tags")
suspend fun deleteAll()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ivy.data.db.dao.write

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.ivy.data.db.entity.TagTransactionEntity
import java.util.*

@Dao
interface WriteTagTransactionDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(value: TagTransactionEntity)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun save(value: List<TagTransactionEntity>)

@Query("DELETE FROM tags_transaction")
suspend fun deleteAll()

@Query("DELETE FROM tags_transaction WHERE tagId = :tagId AND associatedId = :associatedId")
suspend fun deleteId(tagId: UUID, associatedId: UUID)

@Query("DELETE FROM tags_transaction WHERE tagId = :tagId")
suspend fun deleteAssociationsByTagId(tagId: UUID)

@Query("DELETE FROM tags_transaction WHERE associatedId = :associatedId")
suspend fun deleteAssociationsByAssociateId(associatedId: UUID)
}
39 changes: 39 additions & 0 deletions temp-legacy-code/src/main/java/com/ivy/legacy/datamodel/Tag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ivy.legacy.datamodel

import com.ivy.data.db.entity.TagEntity
import java.time.LocalDateTime
import java.util.UUID

data class Tag(
val id: UUID = UUID.randomUUID(),

val name: String,
val description: String? = null,

val color: Int,
val icon: String? = null,
val orderNum: Double = 0.0,

val dateTime: LocalDateTime? = null,
val isSynced: Boolean = false,
val isDeleted: Boolean = false,

val featureBit: Int = 0,
val featureBitValue: String? = null
) {
fun toEntity(): TagEntity {
return TagEntity(
id,
name,
description,
color,
icon,
orderNum,
isSynced,
isDeleted,
dateTime,
featureBit,
featureBitValue
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ivy.legacy.datamodel

import com.ivy.data.db.entity.TagTransactionEntity
import java.util.*


data class TagTransaction(
val tagId: UUID,
val associatedId: UUID,
val isSynced: Boolean = false,
val isDeleted: Boolean = false
) {
fun toEntity(): TagTransactionEntity {
return TagTransactionEntity(tagId, associatedId, isSynced, isDeleted)
}
}

0 comments on commit 32f34ac

Please sign in to comment.