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

Commit

Permalink
[IVY-2863] Fix Tags Detekt Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwa-Raghavendra committed Feb 4, 2024
1 parent 1f808a9 commit 53c1946
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import com.ivy.domain.db.migration.Migration125to126_Tags
AccountEntity::class, TransactionEntity::class, CategoryEntity::class,
SettingsEntity::class, PlannedPaymentRuleEntity::class,
UserEntity::class, ExchangeRateEntity::class, BudgetEntity::class,
LoanEntity::class, LoanRecordEntity::class,TagEntity::class,TagAssociationEntity::class
LoanEntity::class, LoanRecordEntity::class, TagEntity::class, TagAssociationEntity::class
],
autoMigrations = [
AutoMigration(
Expand All @@ -89,8 +89,8 @@ abstract class IvyRoomDatabase : RoomDatabase() {
abstract val exchangeRatesDao: ExchangeRatesDao
abstract val loanDao: LoanDao
abstract val loanRecordDao: LoanRecordDao
abstract val tagDao : TagDao
abstract val tagAssociationDao : TagAssociationDao
abstract val tagDao: TagDao
abstract val tagAssociationDao: TagAssociationDao

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

companion object {
const val DB_NAME = "ivywallet.db"
Expand Down
4 changes: 2 additions & 2 deletions ivy-data/src/main/java/com/ivy/data/db/RoomTypeConverters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class RoomTypeConverters {
fun parseLoanType(value: String?) = value?.let { LoanType.valueOf(it) }

@TypeConverter
fun saveInstant(value: Instant) = value.toEpochMilli()
fun saveInstant(value: Instant): Long = value.toEpochMilli()

@TypeConverter
fun parseInstant(value: Long) = Instant.ofEpochMilli(value)
fun parseInstant(value: Long): Instant = Instant.ofEpochMilli(value)
}
11 changes: 9 additions & 2 deletions ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.ivy.data.db.dao.read

import androidx.room.*
import androidx.room.Dao
import androidx.room.MapColumn
import androidx.room.Query
import androidx.room.RewriteQueriesToDropUnusedColumns
import com.ivy.data.db.entity.TagEntity
import java.util.*

Expand All @@ -12,7 +15,11 @@ interface TagDao {
@Query("SELECT * FROM tags WHERE id = :id")
suspend fun findById(id: UUID): TagEntity?

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.ivy.data.db.dao.write

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
@file:Suppress("InvalidPackageDeclaration")

package com.ivy.domain.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

@Suppress("MagicNumber", "ClassNaming")
class Migration125to126_Tags : Migration(125, 126) {
companion object {
private const val TAGS_TABLE = "tags"
private const val TAGS_ASSOCIATION_TABLE = "tags_association"
}

@Suppress("MaximumLineLength", "MaxLineLength")
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"CREATE TABLE IF NOT EXISTS `${TAGS_TABLE}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `description` TEXT, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `isDeleted` INTEGER NOT NULL, `dateTime` INTEGER NOT NULL, `lastSyncedTime` INTEGER NOT NULL, PRIMARY KEY(`id`))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.ivy.data.model.primitive.TagId
import com.ivy.data.model.sync.Syncable
import java.time.Instant

@Suppress("DataClassTypedIDs")
data class TagAssociation(
override val id: TagId,
val associatedId: AssociationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import com.ivy.data.model.primitive.ColorInt
import com.ivy.data.model.primitive.IconAsset
import com.ivy.data.model.primitive.NotBlankTrimmedString
import com.ivy.data.model.primitive.TagId
import java.time.Instant
import java.time.ZoneId
import java.time.ZoneOffset
import javax.inject.Inject

class TagMapper @Inject constructor() {
Expand All @@ -27,7 +24,7 @@ class TagMapper @Inject constructor() {
)
}

fun Tag.toEntity() : TagEntity {
fun Tag.toEntity(): TagEntity {
return TagEntity(
id = this.id.value,
name = this.name.value,
Expand Down

0 comments on commit 53c1946

Please sign in to comment.