From 53c19467519365a25add74abb65b9fe92c88e459 Mon Sep 17 00:00:00 2001 From: Vishwa Raghavendra K S Date: Sun, 4 Feb 2024 12:56:03 +0530 Subject: [PATCH] [IVY-2863] Fix Tags Detekt Errors --- .../src/main/java/com/ivy/data/db/IvyRoomDatabase.kt | 10 +++++----- .../main/java/com/ivy/data/db/RoomTypeConverters.kt | 4 ++-- .../src/main/java/com/ivy/data/db/dao/read/TagDao.kt | 11 +++++++++-- .../java/com/ivy/data/db/dao/write/WriteTagDao.kt | 6 +++++- .../ivy/data/db/migration/Migration125to126_Tags.kt | 4 ++++ .../main/java/com/ivy/data/model/TagAssociation.kt | 1 + .../java/com/ivy/data/repository/mapper/TagMapper.kt | 5 +---- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt b/ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt index b0390cefa4..5d8f4fcd7d 100644 --- a/ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt +++ b/ivy-data/src/main/java/com/ivy/data/db/IvyRoomDatabase.kt @@ -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( @@ -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 @@ -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" diff --git a/ivy-data/src/main/java/com/ivy/data/db/RoomTypeConverters.kt b/ivy-data/src/main/java/com/ivy/data/db/RoomTypeConverters.kt index 38e3fcf080..ed1528dfb9 100644 --- a/ivy-data/src/main/java/com/ivy/data/db/RoomTypeConverters.kt +++ b/ivy-data/src/main/java/com/ivy/data/db/RoomTypeConverters.kt @@ -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) } diff --git a/ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt b/ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt index 6769437c69..13734fcc89 100644 --- a/ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt +++ b/ivy-data/src/main/java/com/ivy/data/db/dao/read/TagDao.kt @@ -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.* @@ -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): Map<@MapColumn(columnName = "id") UUID, List> diff --git a/ivy-data/src/main/java/com/ivy/data/db/dao/write/WriteTagDao.kt b/ivy-data/src/main/java/com/ivy/data/db/dao/write/WriteTagDao.kt index 88cf649e8c..d5ff7c497a 100644 --- a/ivy-data/src/main/java/com/ivy/data/db/dao/write/WriteTagDao.kt +++ b/ivy-data/src/main/java/com/ivy/data/db/dao/write/WriteTagDao.kt @@ -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.* diff --git a/ivy-data/src/main/java/com/ivy/data/db/migration/Migration125to126_Tags.kt b/ivy-data/src/main/java/com/ivy/data/db/migration/Migration125to126_Tags.kt index f88a7d4252..338e3e717d 100644 --- a/ivy-data/src/main/java/com/ivy/data/db/migration/Migration125to126_Tags.kt +++ b/ivy-data/src/main/java/com/ivy/data/db/migration/Migration125to126_Tags.kt @@ -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`))" diff --git a/ivy-data/src/main/java/com/ivy/data/model/TagAssociation.kt b/ivy-data/src/main/java/com/ivy/data/model/TagAssociation.kt index 5d87ee5728..6be1a49b13 100644 --- a/ivy-data/src/main/java/com/ivy/data/model/TagAssociation.kt +++ b/ivy-data/src/main/java/com/ivy/data/model/TagAssociation.kt @@ -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, diff --git a/ivy-data/src/main/java/com/ivy/data/repository/mapper/TagMapper.kt b/ivy-data/src/main/java/com/ivy/data/repository/mapper/TagMapper.kt index e96ee0fb23..2ccc5ce55a 100644 --- a/ivy-data/src/main/java/com/ivy/data/repository/mapper/TagMapper.kt +++ b/ivy-data/src/main/java/com/ivy/data/repository/mapper/TagMapper.kt @@ -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() { @@ -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,