Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/refactor-rawdb' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinj07 committed Dec 6, 2023
2 parents 7ca98c1 + 83d9e71 commit 5f6d04a
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/swpp-2023-project-team-10.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
}
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()
}

}
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
)
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>
}
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
)
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>
}

0 comments on commit 5f6d04a

Please sign in to comment.