-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/refactor-rawdb' into dev
- Loading branch information
Showing
10 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlan.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,12 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
sealed interface RawPlan { | ||
val id: Int | ||
val title: String | ||
val memo: String | ||
val categoryId: Int? | ||
val repeatGroupId: Int? | ||
val priority: Int // if 0, raw-sql input | ||
val showInMonthlyView: Boolean | ||
val isOverridden: Boolean | ||
} |
20 changes: 20 additions & 0 deletions
20
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlanRepository.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,20 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
import com.example.calendy.data.maindb.plan.Plan | ||
import com.example.calendy.data.maindb.plan.Schedule | ||
import com.example.calendy.data.maindb.plan.Todo | ||
|
||
class RawPlanRepository (private val rawScheduleDao: RawScheduleDao, | ||
private val rawTodoDao: RawTodoDao | ||
) { | ||
fun getAllPlans(): List<Plan> = | ||
rawScheduleDao.getAllRawSchedules().map { it.toSchedule() } + | ||
rawTodoDao.getAllRawTodos().map { it.toTodo() } | ||
|
||
|
||
fun deleteAll() { | ||
rawScheduleDao.deleteAllRawSchedules() | ||
rawTodoDao.deleteAllRawTodos() | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawSchedule.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,61 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.example.calendy.data.maindb.plan.Schedule | ||
import java.util.Date | ||
|
||
|
||
@Entity( | ||
tableName = "raw_schedule", | ||
) | ||
data class RawSchedule( | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo(name = "id") | ||
override val id: Int = 0, | ||
@ColumnInfo(name = "title") | ||
override val title: String, | ||
@ColumnInfo(name = "start_time") | ||
val startTime: Date, | ||
@ColumnInfo(name = "end_time") | ||
val endTime: Date, | ||
@ColumnInfo(name = "memo", defaultValue = "") | ||
override val memo: String = "", | ||
@ColumnInfo(name = "repeat_group_id", defaultValue = "NULL") | ||
override val repeatGroupId: Int? = null, | ||
@ColumnInfo(name = "category_id", defaultValue = "NULL") | ||
override val categoryId: Int? = null, | ||
@ColumnInfo(name = "priority", defaultValue = "0") // 0 = raw-sql without priority specified | ||
override val priority: Int = 3, | ||
@ColumnInfo(name = "show_in_monthly_view", defaultValue = "1") | ||
override val showInMonthlyView: Boolean = true, | ||
@ColumnInfo(name = "is_overridden", defaultValue = "0") | ||
override val isOverridden: Boolean = false | ||
) : RawPlan { | ||
fun toSchedule(): Schedule = Schedule( | ||
id = id, // Should use same id for successful update | ||
title = title, | ||
startTime = startTime, | ||
endTime = endTime, | ||
memo = memo, | ||
repeatGroupId = repeatGroupId, | ||
categoryId = categoryId, | ||
priority = priority, | ||
showInMonthlyView = showInMonthlyView, | ||
isOverridden = isOverridden | ||
) | ||
} | ||
|
||
fun Schedule.toRawSchedule() = RawSchedule( | ||
id = id, // Should use same id for successful update | ||
title = title, | ||
startTime = startTime, | ||
endTime = endTime, | ||
memo = memo, | ||
repeatGroupId = repeatGroupId, | ||
categoryId = categoryId, | ||
priority = priority, | ||
showInMonthlyView = showInMonthlyView, | ||
isOverridden = isOverridden | ||
) |
14 changes: 14 additions & 0 deletions
14
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawScheduleDao.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,14 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import com.example.calendy.data.BaseDao | ||
|
||
@Dao | ||
interface RawScheduleDao : BaseDao<RawSchedule> { | ||
@Query("DELETE FROM raw_schedule") | ||
fun deleteAllRawSchedules() | ||
|
||
@Query("SELECT * FROM raw_schedule") | ||
fun getAllRawSchedules(): List<RawSchedule> | ||
} |
61 changes: 61 additions & 0 deletions
61
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodo.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,61 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.example.calendy.data.maindb.plan.Todo | ||
import java.util.Date | ||
|
||
// table name tod0(=t0do) in 'calendy_database.db' | ||
@Entity( | ||
tableName = "raw_todo" | ||
) | ||
data class RawTodo( | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo(name = "id") | ||
override val id: Int = 0, | ||
@ColumnInfo(name = "title") | ||
override val title: String, | ||
@ColumnInfo(name = "due_time") | ||
val dueTime: Date, | ||
@ColumnInfo(name = "complete", defaultValue = "0") | ||
val complete: Boolean = false, | ||
@ColumnInfo(name = "memo", defaultValue = "") | ||
override val memo: String = "", | ||
@ColumnInfo(name = "repeat_group_id", defaultValue = "NULL") | ||
override val repeatGroupId: Int? = null, | ||
@ColumnInfo(name = "category_id", defaultValue = "NULL") | ||
override val categoryId: Int? = null, | ||
@ColumnInfo(name = "priority", defaultValue = "0") // 0 = raw-sql without priority specified | ||
override val priority: Int = 3, | ||
@ColumnInfo(name = "show_in_monthly_view", defaultValue = "1") | ||
override val showInMonthlyView: Boolean = true, | ||
@ColumnInfo(name = "is_overridden", defaultValue = "0") | ||
override val isOverridden: Boolean = false | ||
) : RawPlan { | ||
fun toTodo(): Todo = Todo( | ||
id = id, // Should use same id for successful update | ||
title = title, | ||
dueTime = dueTime, | ||
complete = complete, | ||
memo = memo, | ||
repeatGroupId = repeatGroupId, | ||
categoryId = categoryId, | ||
priority = priority, | ||
showInMonthlyView = showInMonthlyView, | ||
isOverridden = isOverridden | ||
) | ||
} | ||
|
||
fun Todo.toRawTodo(): RawTodo = RawTodo( | ||
id = id, // Should use same id for successful update | ||
title = title, | ||
dueTime = dueTime, | ||
complete = complete, | ||
memo = memo, | ||
repeatGroupId = repeatGroupId, | ||
categoryId = categoryId, | ||
priority = priority, | ||
showInMonthlyView = showInMonthlyView, | ||
isOverridden = isOverridden | ||
) |
14 changes: 14 additions & 0 deletions
14
frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodoDao.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,14 @@ | ||
package com.example.calendy.data.maindb.rawplan | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import com.example.calendy.data.BaseDao | ||
|
||
@Dao | ||
interface RawTodoDao : BaseDao<RawTodo> { | ||
@Query("DELETE FROM raw_todo") | ||
fun deleteAllRawTodos() | ||
|
||
@Query("SELECT * FROM raw_todo") | ||
fun getAllRawTodos(): List<RawTodo> | ||
} |