-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use separate entities in domain and data layers.
- Loading branch information
1 parent
3550347
commit 764992c
Showing
33 changed files
with
107 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...cker/jettasks/data/local/DateConverter.kt → ...vnathacker/jettasks/data/DateConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...vnathacker/jettasks/data/local/TaskDao.kt → ...havnathacker/jettasks/data/dao/TaskDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package com.bhavnathacker.jettasks.data.local | ||
package com.bhavnathacker.jettasks.data.dao | ||
|
||
import androidx.room.* | ||
import com.bhavnathacker.jettasks.domain.model.Task | ||
import com.bhavnathacker.jettasks.data.model.DBTask | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface TaskDao { | ||
@Query("SELECT * FROM task_tbl ORDER BY id DESC") | ||
fun getTasks(): Flow<List<Task>> | ||
fun getTasks(): Flow<List<DBTask>> | ||
|
||
@Query("SELECT * FROM task_tbl where id = :id") | ||
suspend fun getTask(id: Int?): Task? | ||
suspend fun getTask(id: Int?): DBTask? | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(task: Task) | ||
suspend fun insert(task: DBTask) | ||
|
||
@Query("DELETE FROM task_tbl") | ||
suspend fun deleteAll() | ||
|
||
@Delete | ||
suspend fun deleteTask(task: Task) | ||
suspend fun deleteTask(task: DBTask) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/bhavnathacker/jettasks/data/database/TaskDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.bhavnathacker.jettasks.data.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import com.bhavnathacker.jettasks.data.DateConverter | ||
import com.bhavnathacker.jettasks.data.dao.TaskDao | ||
import com.bhavnathacker.jettasks.data.model.DBTask | ||
import com.bhavnathacker.jettasks.domain.entity.Task | ||
|
||
@Database(entities = [DBTask::class], version = 1, exportSchema = false) | ||
@TypeConverters(DateConverter::class) | ||
abstract class TaskDatabase : RoomDatabase() { | ||
abstract fun taskDao(): TaskDao | ||
} |
12 changes: 0 additions & 12 deletions
12
app/src/main/java/com/bhavnathacker/jettasks/data/local/TaskDatabase.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/bhavnathacker/jettasks/data/model/DBTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.bhavnathacker.jettasks.data.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.bhavnathacker.jettasks.domain.entity.Task | ||
import com.bhavnathacker.jettasks.domain.entity.TaskPriority | ||
import com.bhavnathacker.jettasks.domain.entity.TaskStatus | ||
import java.util.Date | ||
|
||
@Entity(tableName = "task_tbl") | ||
data class DBTask( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Int = 0, | ||
var name: String, | ||
var deadline: Date, | ||
var priority: TaskPriority, | ||
var status: TaskStatus | ||
) | ||
|
||
fun DBTask?.toTask(): Task? = this?.let { | ||
Task(id = it.id, name = it.name, deadline = it.deadline, priority = it.priority, status = it.status) | ||
} | ||
|
||
fun Task.toDBTask(): DBTask = DBTask(id = this.id, name = this.name, deadline = this.deadline, priority = this.priority, status = this.status) |
28 changes: 15 additions & 13 deletions
28
app/src/main/java/com/bhavnathacker/jettasks/data/repository/DefaultTaskRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package com.bhavnathacker.jettasks.data.repository | ||
|
||
import com.bhavnathacker.jettasks.data.local.TaskDao | ||
import com.bhavnathacker.jettasks.domain.model.Task | ||
import com.bhavnathacker.jettasks.data.dao.TaskDao | ||
import com.bhavnathacker.jettasks.data.mapper.DBTaskMapper | ||
import com.bhavnathacker.jettasks.data.mapper.TaskMapper | ||
import com.bhavnathacker.jettasks.data.model.toDBTask | ||
import com.bhavnathacker.jettasks.data.model.toTask | ||
import com.bhavnathacker.jettasks.domain.entity.Task | ||
import com.bhavnathacker.jettasks.domain.repository.TaskRepository | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.conflate | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.* | ||
import javax.inject.Inject | ||
|
||
class DefaultTaskRepository @Inject constructor(private val taskDao: TaskDao): TaskRepository { | ||
override suspend fun saveTask(task: Task) = taskDao.insert(task) | ||
override suspend fun deleteTask(task: Task) = taskDao.deleteTask(task) | ||
override suspend fun getTask(id: Int?): Task? = taskDao.getTask(id) | ||
override fun getAllTasks(): Flow<List<Task>> = taskDao.getTasks().flowOn(Dispatchers.IO) | ||
.conflate() | ||
|
||
class DefaultTaskRepository @Inject constructor( | ||
private val taskDao: TaskDao) : TaskRepository { | ||
override suspend fun saveTask(task: Task) = taskDao.insert(task.toDBTask()) | ||
override suspend fun deleteTask(task: Task) = taskDao.deleteTask(task.toDBTask()) | ||
override suspend fun getTask(id: Int?): Task? = taskDao.getTask(id).toTask() | ||
override fun getAllTasks(): Flow<List<Task>> = taskDao.getTasks().map { list -> | ||
list.map { (it.toTask())!! } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
app/src/main/java/com/bhavnathacker/jettasks/di/PreferencesUseCasesModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 3 additions & 16 deletions
19
app/src/main/java/com/bhavnathacker/jettasks/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
...avnathacker/jettasks/domain/model/Task.kt → ...vnathacker/jettasks/domain/entity/Task.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ker/jettasks/domain/model/TaskPriority.kt → ...er/jettasks/domain/entity/TaskPriority.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...acker/jettasks/domain/model/TaskStatus.kt → ...cker/jettasks/domain/entity/TaskStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/repository/TaskRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/DefaultDeleteTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/DefaultGetTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/DefaultGetTasks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/DefaultSaveTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/DeleteTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/GetTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/GetTasks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/domain/use_cases/SaveTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/src/main/java/com/bhavnathacker/jettasks/presentation/events/TaskDetailEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/bhavnathacker/jettasks/presentation/events/TaskListEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.