From 83d9e7113b497ab9b21dd02c9419a6fc5331514b Mon Sep 17 00:00:00 2001 From: darwinj07 Date: Sun, 3 Dec 2023 03:41:24 +0900 Subject: [PATCH] rename rawsqldb to rawdb and integrate into maindb --- .idea/modules.xml | 8 +++ .idea/swpp-2023-project-team-10.iml | 9 +++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 43 +++++++++++++ .../calendy/data/maindb/rawplan/RawPlan.kt | 12 ++++ .../data/maindb/rawplan/RawPlanRepository.kt | 20 ++++++ .../data/maindb/rawplan/RawSchedule.kt | 61 +++++++++++++++++++ .../data/maindb/rawplan/RawScheduleDao.kt | 14 +++++ .../calendy/data/maindb/rawplan/RawTodo.kt | 61 +++++++++++++++++++ .../calendy/data/maindb/rawplan/RawTodoDao.kt | 14 +++++ 10 files changed, 248 insertions(+) create mode 100644 .idea/modules.xml create mode 100644 .idea/swpp-2023-project-team-10.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlan.kt create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlanRepository.kt create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawSchedule.kt create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawScheduleDao.kt create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodo.kt create mode 100644 frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodoDao.kt diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..908f1d4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/swpp-2023-project-team-10.iml b/.idea/swpp-2023-project-team-10.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/swpp-2023-project-team-10.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..b5e34da --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + 1701328154283 + + + + \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlan.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlan.kt new file mode 100644 index 0000000..26f6c78 --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlan.kt @@ -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 +} \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlanRepository.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlanRepository.kt new file mode 100644 index 0000000..df2efa3 --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawPlanRepository.kt @@ -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 = + rawScheduleDao.getAllRawSchedules().map { it.toSchedule() } + + rawTodoDao.getAllRawTodos().map { it.toTodo() } + + + fun deleteAll() { + rawScheduleDao.deleteAllRawSchedules() + rawTodoDao.deleteAllRawTodos() + } + + } diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawSchedule.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawSchedule.kt new file mode 100644 index 0000000..af25ac3 --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawSchedule.kt @@ -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 +) \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawScheduleDao.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawScheduleDao.kt new file mode 100644 index 0000000..6322ffd --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawScheduleDao.kt @@ -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 { + @Query("DELETE FROM raw_schedule") + fun deleteAllRawSchedules() + + @Query("SELECT * FROM raw_schedule") + fun getAllRawSchedules(): List +} \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodo.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodo.kt new file mode 100644 index 0000000..2142a68 --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodo.kt @@ -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 +) \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodoDao.kt b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodoDao.kt new file mode 100644 index 0000000..956aa94 --- /dev/null +++ b/frontend/app/src/main/java/com/example/calendy/data/maindb/rawplan/RawTodoDao.kt @@ -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 { + @Query("DELETE FROM raw_todo") + fun deleteAllRawTodos() + + @Query("SELECT * FROM raw_todo") + fun getAllRawTodos(): List +} \ No newline at end of file