Skip to content

Commit

Permalink
Merge pull request #1 from suyash01/feature/emi
Browse files Browse the repository at this point in the history
emi functionality
  • Loading branch information
suyash01 authored Jan 26, 2024
2 parents e048205 + 88f40dd commit 8160cce
Show file tree
Hide file tree
Showing 40 changed files with 1,132 additions and 65 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId = "com.suyash.creditmanager"
minSdk = 26
targetSdk = 34
versionCode = 3
versionName = "1.0.2"
versionCode = 4
versionName = "1.0.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "b8f60b83fc59ce0e4a162b2b304895b1",
"identityHash": "efabf04763a0c05c6fa15fce67ac3c32",
"entities": [
{
"tableName": "credit_cards",
Expand Down Expand Up @@ -124,7 +124,7 @@
"views": [],
"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, 'b8f60b83fc59ce0e4a162b2b304895b1')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'efabf04763a0c05c6fa15fce67ac3c32')"
]
}
}
186 changes: 186 additions & 0 deletions app/schemas/com.suyash.creditmanager.data.source.CreditDatabase/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "efabf04763a0c05c6fa15fce67ac3c32",
"entities": [
{
"tableName": "credit_cards",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cardName` TEXT NOT NULL, `last4Digits` TEXT NOT NULL, `expiryDate` TEXT NOT NULL, `billDate` INTEGER NOT NULL, `dueDate` INTEGER NOT NULL, `cardType` TEXT NOT NULL, `limit` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "cardName",
"columnName": "cardName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "last4Digits",
"columnName": "last4Digits",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "expiryDate",
"columnName": "expiryDate",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "billDate",
"columnName": "billDate",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "dueDate",
"columnName": "dueDate",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "cardType",
"columnName": "cardType",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "limit",
"columnName": "limit",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "transactions",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`type` TEXT NOT NULL, `amount` REAL NOT NULL, `card` INTEGER NOT NULL, `date` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "card",
"columnName": "card",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_transactions_date",
"unique": false,
"columnNames": [
"date"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_transactions_date` ON `${TABLE_NAME}` (`date`)"
}
],
"foreignKeys": []
},
{
"tableName": "emis",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `rate` REAL NOT NULL, `months` INTEGER NOT NULL, `card` INTEGER, `date` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "rate",
"columnName": "rate",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "months",
"columnName": "months",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "card",
"columnName": "card",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"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, 'efabf04763a0c05c6fa15fce67ac3c32')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.suyash.creditmanager.data.repository

import com.suyash.creditmanager.data.source.dao.EMIDao
import com.suyash.creditmanager.domain.model.EMI
import com.suyash.creditmanager.domain.repository.EMIRepository
import kotlinx.coroutines.flow.Flow

class EMIRepositoryImpl(private val dao: EMIDao): EMIRepository {
override suspend fun upsertEMI(emi: EMI) {
dao.upsertEMI(emi)
}

override suspend fun deleteEMI(emi: EMI) {
dao.deleteEMI(emi)
}

override fun getEMIs(): Flow<List<EMI>> {
return dao.getEMIs()
}

override suspend fun getEMI(id: Int): EMI? {
return dao.getEMI(id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import com.suyash.creditmanager.data.source.dao.CreditCardDao
import com.suyash.creditmanager.data.source.dao.EMIDao
import com.suyash.creditmanager.data.source.dao.TransactionDao
import com.suyash.creditmanager.domain.model.CreditCard
import com.suyash.creditmanager.domain.model.EMI
import com.suyash.creditmanager.domain.model.Transaction

@Database(
entities = [CreditCard::class, Transaction::class],
version = 2,
entities = [CreditCard::class, Transaction::class, EMI::class],
version = 3,
autoMigrations = [
AutoMigration(from = 1, to = 2)
AutoMigration(from = 1, to = 2),
AutoMigration(from = 2, to = 3)
]
)
abstract class CreditDatabase: RoomDatabase() {

abstract val creditCardDao: CreditCardDao
abstract val transactionDao: TransactionDao
abstract val emiDao: EMIDao

companion object {
const val DATABASE_NAME = "credit_db"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.suyash.creditmanager.data.source.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Query
import androidx.room.Upsert
import com.suyash.creditmanager.domain.model.EMI
import kotlinx.coroutines.flow.Flow

@Dao
interface EMIDao {
@Upsert
suspend fun upsertEMI(emi: EMI)

@Delete
suspend fun deleteEMI(emi: EMI)

@Query("SELECT * FROM emis")
fun getEMIs(): Flow<List<EMI>>

@Query("SELECT * FROM emis WHERE id = :id")
suspend fun getEMI(id: Int): EMI?
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/suyash/creditmanager/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ import androidx.datastore.core.DataStoreFactory
import androidx.datastore.dataStoreFile
import androidx.room.Room
import com.suyash.creditmanager.data.repository.CreditCardRepositoryImpl
import com.suyash.creditmanager.data.repository.EMIRepositoryImpl
import com.suyash.creditmanager.data.repository.TransactionRepositoryImpl
import com.suyash.creditmanager.data.settings.AppSettings
import com.suyash.creditmanager.data.settings.AppSettingsSerializer
import com.suyash.creditmanager.data.source.CreditDatabase
import com.suyash.creditmanager.domain.repository.CreditCardRepository
import com.suyash.creditmanager.domain.repository.EMIRepository
import com.suyash.creditmanager.domain.repository.TransactionRepository
import com.suyash.creditmanager.domain.use_case.credit_card.AddCreditCard
import com.suyash.creditmanager.domain.use_case.CreditCardUseCases
import com.suyash.creditmanager.domain.use_case.EMIUseCases
import com.suyash.creditmanager.domain.use_case.TransactionUseCase
import com.suyash.creditmanager.domain.use_case.credit_card.DeleteCreditCard
import com.suyash.creditmanager.domain.use_case.credit_card.GetCreditCard
import com.suyash.creditmanager.domain.use_case.credit_card.GetCreditCards
import com.suyash.creditmanager.domain.use_case.emi.AddEMI
import com.suyash.creditmanager.domain.use_case.emi.DeleteEMI
import com.suyash.creditmanager.domain.use_case.emi.GetEMI
import com.suyash.creditmanager.domain.use_case.emi.GetEMIs
import com.suyash.creditmanager.domain.use_case.transaction.AddTransaction
import com.suyash.creditmanager.domain.use_case.transaction.DeleteTransaction
import com.suyash.creditmanager.domain.use_case.transaction.GetTransaction
Expand Down Expand Up @@ -48,6 +55,7 @@ object AppModule {
@Provides
@Singleton
fun provideCreditCardRepository(db: CreditDatabase): CreditCardRepository {
db.openHelper.writableDatabase
return CreditCardRepositoryImpl(db.creditCardDao)
}

Expand All @@ -57,6 +65,12 @@ object AppModule {
return TransactionRepositoryImpl(db.transactionDao)
}

@Provides
@Singleton
fun provideEMIRepository(db: CreditDatabase): EMIRepository {
return EMIRepositoryImpl(db.emiDao)
}

@Provides
@Singleton
fun provideCreditCardUseCases(repository: CreditCardRepository): CreditCardUseCases {
Expand All @@ -79,6 +93,17 @@ object AppModule {
)
}

@Provides
@Singleton
fun provideEMIUseCases(repository: EMIRepository): EMIUseCases {
return EMIUseCases(
getEMIs = GetEMIs(repository),
getEMI = GetEMI(repository),
upsertEMI = AddEMI(repository),
deleteEMI = DeleteEMI(repository)
)
}

@Singleton
@Provides
fun provideProtoDataStore(@ApplicationContext appContext: Context): DataStore<AppSettings> {
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/suyash/creditmanager/domain/model/EMI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.suyash.creditmanager.domain.model

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import java.time.LocalDate

@Entity(
tableName = "emis"
)
@TypeConverters(Converters::class)
data class EMI(
val name: String,
val amount: Float,
val rate: Float,
val months: Int,
val card: Int?,
val date: LocalDate,
@PrimaryKey(autoGenerate = true)
val id: Int = 0
)

class InvalidEMIException(message: String): Exception(message)
Loading

0 comments on commit 8160cce

Please sign in to comment.