Commit 30ec5462 authored by Filip Wiesner's avatar Filip Wiesner

FIX: Multiple notes for one event -> unique FK

parent c3e193bc
......@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 8,
"identityHash": "daf76b7313a919dccf691f6e1d7adc9f",
"identityHash": "37125790ad99f4a37db3a5a5401a8f52",
"entities": [
{
"tableName": "Event",
......@@ -140,7 +140,16 @@
],
"autoGenerate": true
},
"indices": [],
"indices": [
{
"name": "index_EventNote_eventId",
"unique": true,
"columnNames": [
"eventId"
],
"createSql": "CREATE UNIQUE INDEX `index_EventNote_eventId` ON `${TABLE_NAME}` (`eventId`)"
}
],
"foreignKeys": []
},
{
......@@ -294,7 +303,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"daf76b7313a919dccf691f6e1d7adc9f\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"37125790ad99f4a37db3a5a5401a8f52\")"
]
}
}
\ No newline at end of file
{
"formatVersion": 1,
"database": {
"version": 9,
"identityHash": "37125790ad99f4a37db3a5a5401a8f52",
"entities": [
{
"tableName": "Event",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `sequenceNum` INTEGER NOT NULL, `startsAt` INTEGER NOT NULL, `endsAt` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, `capacity` INTEGER NOT NULL, `occupied` INTEGER NOT NULL, `eventTypeRaw` TEXT NOT NULL, `parallel` TEXT NOT NULL, `cs` TEXT, `en` TEXT, `course` TEXT, `room` TEXT, `teachers` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "sequenceNum",
"columnName": "sequenceNum",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "startsAt",
"columnName": "startsAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "endsAt",
"columnName": "endsAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "deleted",
"columnName": "deleted",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "capacity",
"columnName": "capacity",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "occupied",
"columnName": "occupied",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "eventTypeRaw",
"columnName": "eventTypeRaw",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "parallel",
"columnName": "parallel",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "note.cs",
"columnName": "cs",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "note.en",
"columnName": "en",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.course",
"columnName": "course",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.room",
"columnName": "room",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linked.teachers",
"columnName": "teachers",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_Event_eventTypeRaw",
"unique": false,
"columnNames": [
"eventTypeRaw"
],
"createSql": "CREATE INDEX `index_Event_eventTypeRaw` ON `${TABLE_NAME}` (`eventTypeRaw`)"
}
],
"foreignKeys": []
},
{
"tableName": "EventNote",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`noteId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `eventId` INTEGER NOT NULL, `note` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "noteId",
"columnName": "noteId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "eventId",
"columnName": "eventId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "note",
"columnName": "note",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"noteId"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_EventNote_eventId",
"unique": true,
"columnNames": [
"eventId"
],
"createSql": "CREATE UNIQUE INDEX `index_EventNote_eventId` ON `${TABLE_NAME}` (`eventId`)"
}
],
"foreignKeys": []
},
{
"tableName": "Course",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`code` TEXT NOT NULL, `completion` TEXT NOT NULL, `credits` INTEGER NOT NULL, `department` TEXT NOT NULL, `homepage` TEXT, `name` TEXT NOT NULL, `range` TEXT NOT NULL, `season` TEXT NOT NULL, `state` TEXT NOT NULL, `studyForm` TEXT, PRIMARY KEY(`code`))",
"fields": [
{
"fieldPath": "code",
"columnName": "code",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "completion",
"columnName": "completion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "credits",
"columnName": "credits",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "department",
"columnName": "department",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "homepage",
"columnName": "homepage",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "range",
"columnName": "range",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "season",
"columnName": "season",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "state",
"columnName": "state",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "studyForm",
"columnName": "studyForm",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"code"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "Teacher",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`firstName` TEXT NOT NULL, `lastName` TEXT NOT NULL, `personalNumber` INTEGER NOT NULL, `titlesPost` TEXT, `titlesPre` TEXT, `username` TEXT NOT NULL, `division` TEXT NOT NULL, `email` TEXT NOT NULL, `extern` INTEGER NOT NULL, `phone` TEXT, PRIMARY KEY(`username`))",
"fields": [
{
"fieldPath": "firstName",
"columnName": "firstName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastName",
"columnName": "lastName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "personalNumber",
"columnName": "personalNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "titlesPost",
"columnName": "titlesPost",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "titlesPre",
"columnName": "titlesPre",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "division",
"columnName": "division",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "email",
"columnName": "email",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "extern",
"columnName": "extern",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "phone",
"columnName": "phone",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"username"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"37125790ad99f4a37db3a5a5401a8f52\")"
]
}
}
\ No newline at end of file
......@@ -57,11 +57,6 @@ class TasksFragment : Fragment() {
private fun setupBinding() {
bind(viewModel.tasks) toPassValueTo taskAdapter::submitList
observe(viewModel.tasks) {
log(it.toString())
}
observe(viewModel.refreshResult) {
Log.d(BlackBirdAC.LOG_TAG, (it as? Failure)?.message ?: it.toString())
}
......
......@@ -14,7 +14,7 @@ import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
@Database(entities = [Event::class, EventNote::class, Course::class, Teacher::class], version = 8)
@Database(entities = [Event::class, EventNote::class, Course::class, Teacher::class], version = 9)
@TypeConverters(DBTypeConverters::class)
abstract class BlackBirdDB: RoomDatabase() {
abstract fun eventDao(): EventDao
......
......@@ -2,8 +2,8 @@ package com.cvut.blackbird.model.entities
import androidx.room.*
@Entity
class EventNote(
@Entity(indices = [Index(value = ["eventId"], unique = true)])
data class EventNote(
@PrimaryKey(autoGenerate = true)
val noteId: Int,
......
......@@ -13,15 +13,12 @@ class EventDetailModel: BlackBirdModel() {
init { BlackBirdAC.graph.inject(this) }
suspend fun getDetailedEvent(eventId: Int) = eventDao.getDetailedEvent(eventId)
.apply {
suspend fun getDetailedEvent(eventId: Int) =
eventDao.getDetailedEvent(eventId).apply {
initTeachers(teacherDao)
}
suspend fun updateNote(eventNote: EventNote) {
eventDao.saveEventNote(eventNote)
}
suspend fun createNote(eventId: Int) = EventNote(eventId)
.apply { eventDao.saveEventNote(this) }
}
\ No newline at end of file
......@@ -6,23 +6,24 @@ import androidx.lifecycle.MutableLiveData
import com.chibatching.kotpref.livedata.asLiveData
import com.cvut.blackbird.BlackBirdAC
import com.cvut.blackbird.extensions.passTo
import com.cvut.blackbird.model.*
import com.cvut.blackbird.model.BlackBirdModel
import com.cvut.blackbird.model.Failure
import com.cvut.blackbird.model.Result
import com.cvut.blackbird.model.Success
import com.cvut.blackbird.model.database.EventDao
import com.cvut.blackbird.model.entities.DetailedEvent
import com.cvut.blackbird.model.entities.Event
import com.cvut.blackbird.model.entities.News
import com.cvut.blackbird.model.entities.NewsRoot
import com.cvut.blackbird.model.services.*
import com.cvut.blackbird.model.services.EventsMeta
import com.cvut.blackbird.model.services.SiriusService
import com.tickaroo.tikxml.TikXml
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.android.Main
import kotlinx.coroutines.android.UI
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import java.lang.Exception
import javax.inject.Inject
@Suppress("RedundantSuspendModifier")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment