Skip to content

Commit

Permalink
Connect the app to Database layer. (#1)
Browse files Browse the repository at this point in the history
* added : Database source

* added : BoardListCardLabelEntity relation model

* fix: KSP Compile time issues.

* feat: Add Board implemented

* fix: ListDetail Scaffold for CardDetailScreen

* insert: Card to DB base.

* insert: List to DB base.

* remove: Static data from Dashboard Screen.

* remove: Static data from TaskboardScreen.

* fix: DB Relationship with List and Card entities
  • Loading branch information
nikeight authored Aug 23, 2024
1 parent 7bfcaa2 commit 037b32b
Show file tree
Hide file tree
Showing 84 changed files with 1,563 additions and 678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ fun JtbNavHost(
)

createBoardGraph(
onBackClick = onBackClick
onBackClick = onBackClick,
navigateToBoardRoute = {
onNavigateToDestination(
TaskBoardDestination,
TaskBoardDestination.route,
)
}
)

searchGraph(
Expand Down
1 change: 1 addition & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
/* Android Designing and layout */
implementation(platform(libs.androidx.compose.bom))
implementation(libs.compose.material)
// implementation("androidx.test.ext:junit-ktx:1.2.1")

/* Testing */
testImplementation(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jetapps.jettaskboard.di

import android.content.Context
import androidx.room.Room
import com.jetapps.jettaskboard.local.dao.BoardDao
import com.jetapps.jettaskboard.local.dao.DashboardDao
import com.jetapps.jettaskboard.local.dao.CardDao
import com.jetapps.jettaskboard.local.dao.LabelDao
import com.jetapps.jettaskboard.local.dao.ListDao
Expand All @@ -12,6 +12,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Named
import javax.inject.Singleton

@Module
Expand All @@ -20,7 +21,18 @@ object DatabaseModule {

@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): JtbDatabase {
fun provideDatabase(@ApplicationContext context: Context) : JtbDatabase {
return Room.databaseBuilder(
context,
JtbDatabase::class.java,
"tb_db"
).build()
}

@Provides
@Singleton
@Named("test_db")
fun provideTestDatabase(@ApplicationContext context: Context): JtbDatabase {
return Room.inMemoryDatabaseBuilder(
context,
JtbDatabase::class.java
Expand All @@ -29,7 +41,7 @@ object DatabaseModule {

@Provides
@Singleton
fun providesBoardDao(database: JtbDatabase): BoardDao = database.boardDao()
fun providesBoardDao(database: JtbDatabase): DashboardDao = database.boardDao()

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jetapps.jettaskboard.di

import com.jetapps.jettaskboard.local.source.DatabaseSource
import com.jetapps.jettaskboard.local.source.DatabaseSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DatasourceModule {

@Singleton
@Binds
abstract fun bindsDataSourceModule(
datasourceModuleImpl: DatabaseSourceImpl,
): DatabaseSource
}
36 changes: 33 additions & 3 deletions core/data/src/main/java/com/jetapps/jettaskboard/di/RepoModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import com.jetapps.jettaskboard.dispatcher.CoroutineDispatcherProvider
import com.jetapps.jettaskboard.local.dao.CardDao
import com.jetapps.jettaskboard.local.datastore.PreferenceDataStoreSource
import com.jetapps.jettaskboard.local.entity.CardEntity
import com.jetapps.jettaskboard.local.source.DatabaseSource
import com.jetapps.jettaskboard.mapper.BoardMapper
import com.jetapps.jettaskboard.mapper.CardMapper
import com.jetapps.jettaskboard.mapper.EntityMapper
import com.jetapps.jettaskboard.mapper.ListMapper
import com.jetapps.jettaskboard.model.CardModel
import com.jetapps.jettaskboard.model.ChangeBackgroundPhotoModel
import com.jetapps.jettaskboard.model.random.RandomPhotoItemDataModel
Expand All @@ -14,6 +18,8 @@ import com.jetapps.jettaskboard.repo.BoardRepo
import com.jetapps.jettaskboard.repo.BoardRepoImpl
import com.jetapps.jettaskboard.repo.CardRepo
import com.jetapps.jettaskboard.repo.CardRepoImpl
import com.jetapps.jettaskboard.repo.DashboardRepo
import com.jetapps.jettaskboard.repo.DashboardRepoImpl
import com.jetapps.jettaskboard.repo.PhotoRepo
import com.jetapps.jettaskboard.repo.PhotoRepoImpl
import dagger.Module
Expand Down Expand Up @@ -43,7 +49,7 @@ object RepoModule {
fun providePhotoRepo(
photoNetworkResource: PhotoNetworkDataSource,
randomPhotoMapper: EntityMapper<ChangeBackgroundPhotoModel, RandomPhotoItemDataModel>,
searchPhotoMapper : EntityMapper<ChangeBackgroundPhotoModel,ResultImageDataModel>,
searchPhotoMapper: EntityMapper<ChangeBackgroundPhotoModel, ResultImageDataModel>,
dispatcherProvider: CoroutineDispatcherProvider
): PhotoRepo = PhotoRepoImpl(
photoNetwork = photoNetworkResource,
Expand All @@ -55,8 +61,32 @@ object RepoModule {
@Provides
@Singleton
fun provideBoardRepo(
preferenceDataStoreSource: PreferenceDataStoreSource
preferenceDataStoreSource: PreferenceDataStoreSource,
databaseSource: DatabaseSource,
boardMapper: BoardMapper,
listMapper: ListMapper,
cardMapper: CardMapper
): BoardRepo = BoardRepoImpl(
preferenceDataStoreSource = preferenceDataStoreSource
preferenceDataStoreSource = preferenceDataStoreSource,
databaseSource = databaseSource,
boardMapper = boardMapper,
listMapper = listMapper,
cardMapper = cardMapper,
)

@Provides
@Singleton
fun provideDashboardRepo(
databaseSource: DatabaseSource,
boardMapper: BoardMapper,
cardMapper: CardMapper,
listMapper: ListMapper,
): DashboardRepo {
return DashboardRepoImpl(
databaseSource = databaseSource,
boardMapper = boardMapper,
cardMapper = cardMapper,
listMapper = listMapper
)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.jetapps.jettaskboard.local.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.jetapps.jettaskboard.local.entity.BoardEntity
import androidx.room.Transaction
import com.jetapps.jettaskboard.local.entity.CardEntity
import com.jetapps.jettaskboard.local.entity.ListEntity
import com.jetapps.jettaskboard.model.db.BoardWithLists

@Dao
interface BoardDao {

@Query("SELECT * FROM boardTable")
fun getAllBoards(): List<BoardEntity>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertBoard(board: BoardEntity)
}
@Transaction
@Query("SELECT * FROM boardTable WHERE boardId = :boardId")
fun getBoardWithListsAndCards(boardId: Int): BoardWithLists
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.jetapps.jettaskboard.local.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.jetapps.jettaskboard.local.entity.CardEntity
import kotlinx.coroutines.flow.Flow

Expand All @@ -19,12 +21,18 @@ interface CardDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertCard(card: CardEntity)

@Query("SELECT * FROM cardTable where board_id = :boardId")
@Query("SELECT * FROM cardTable where boardId = :boardId")
fun getAllCardsForBoard(boardId: String): Flow<List<CardEntity>>

@Query("SELECT * FROM cardTable where board_id = :boardId and list_id = :listId")
@Query("SELECT * FROM cardTable where boardId = :boardId and listId = :listId")
fun getAllCardsForBoardAndList(
boardId: String,
listId: String
): Flow<List<CardEntity>>

@Update
fun updateCard(card: CardEntity)

@Delete
fun deleteCard(card: CardEntity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.jetapps.jettaskboard.local.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.jetapps.jettaskboard.local.entity.BoardEntity
import com.jetapps.jettaskboard.local.entity.ListEntity
import com.jetapps.jettaskboard.model.db.BoardWithLists
import kotlinx.coroutines.flow.Flow

@Dao
interface DashboardDao {

@Query("SELECT * FROM boardTable")
fun getAllBoards(): Flow<List<BoardEntity>>

@Transaction
@Query("SELECT * FROM boardTable WHERE boardId = :boardId")
fun getBoardDetails(boardId: Int): Flow<BoardWithLists>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertBoard(board: BoardEntity)

@Delete
fun deleteBoard(board: BoardEntity)

@Update
fun markBoardFavourite(board: BoardEntity)

@Query("SELECT title FROM boardTable")
fun getBoardNames(): List<String>

@Query("SELECT * FROM listTable")
fun getAllLists(): List<ListEntity>

@Query("SELECT * FROM listTable where boardId = :boardId")
fun getAllBoardRelatedLists(boardId: Int): List<ListEntity>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetapps.jettaskboard.local.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
Expand All @@ -14,4 +15,7 @@ interface LabelDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertLabel(label: LabelEntity)

@Delete
fun deleteLabel(label: LabelEntity)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetapps.jettaskboard.local.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
Expand All @@ -13,8 +14,11 @@ interface ListDao {
fun getAllLists(): List<ListEntity>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(board: ListEntity)
fun insertList(list: ListEntity)

@Query("SELECT * FROM listTable where board_id = :boardId")
@Delete
fun deleteList(list: ListEntity)

@Query("SELECT * FROM listTable where boardId = :boardId")
fun getAllListsForBoard(boardId: String): List<ListEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jetapps.jettaskboard.local.database

import androidx.room.Database
import androidx.room.RoomDatabase
import com.jetapps.jettaskboard.local.dao.BoardDao
import com.jetapps.jettaskboard.local.dao.DashboardDao
import com.jetapps.jettaskboard.local.dao.CardDao
import com.jetapps.jettaskboard.local.dao.LabelDao
import com.jetapps.jettaskboard.local.dao.ListDao
Expand All @@ -12,6 +12,7 @@ import com.jetapps.jettaskboard.local.entity.CardEntity
import com.jetapps.jettaskboard.local.entity.LabelEntity
import com.jetapps.jettaskboard.local.entity.ListEntity
import com.jetapps.jettaskboard.local.entity.MemberEntity
import com.jetapps.jettaskboard.model.db.ListWithCardCrossRef

@Database(
entities = [
Expand All @@ -20,14 +21,14 @@ import com.jetapps.jettaskboard.local.entity.MemberEntity
BoardEntity::class,
LabelEntity::class,
MemberEntity::class,
AttachmentEntity::class
AttachmentEntity::class,
// ListWithCardCrossRef::class
],
version = 1,
exportSchema = false
)
abstract class JtbDatabase : RoomDatabase() {

abstract fun boardDao(): BoardDao
abstract fun boardDao(): DashboardDao
abstract fun listDao(): ListDao
abstract fun cardDao(): CardDao
abstract fun labelDao(): LabelDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.room.PrimaryKey
tableName = "attachmentTable"
)
data class AttachmentEntity(
@PrimaryKey val id: String,
@PrimaryKey val id: Int,
@ColumnInfo(name = "attachment_name")
val attachmentName: String,
@ColumnInfo(name = "attachment_url")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.jetapps.jettaskboard.local.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(
tableName = "boardTable"
)
data class BoardEntity(
@PrimaryKey val id: String,
@PrimaryKey
val boardId: Int,
val title: String,
val description: String,
@ColumnInfo(name = "work_space_id")
val workSpaceId: String
val isFav : Int,
val workSpaceId : Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,16 @@ import androidx.room.PrimaryKey

@Entity(
tableName = "cardTable"
// foreignKeys = [
// ForeignKey(
// entity = BoardEntity::class,
// parentColumns = ["id"],
// childColumns = ["board_id"],
// onDelete = ForeignKey.CASCADE
// ),
// ForeignKey(
// entity = ListEntity::class,
// parentColumns = ["id"],
// childColumns = ["list_id"],
// onDelete = ForeignKey.CASCADE
// )
// ]
)
data class CardEntity(
@PrimaryKey(autoGenerate = true) val id: Int,
@PrimaryKey(autoGenerate = true)
val cardId: Int,
val title: String,
val description: String?,
@ColumnInfo(name = "column_image_url")
val coverImageUrl: String?,
@ColumnInfo(name = "board_id")
val boardId: String?,
@ColumnInfo(name = "list_id")
val listId: Int?,
val boardId: Int,
val listId: Int,
@ColumnInfo(name = "author_id")
val authorId: String?,
@ColumnInfo(name = "start_date")
Expand Down
Loading

0 comments on commit 037b32b

Please sign in to comment.