mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-18 17:46:44 -06:00
Fix no mobile devices on parent account (#1896)
This commit is contained in:
parent
0f11f14c3e
commit
1b74bffc06
2445
app/schemas/io.github.wulkanowy.data.db.AppDatabase/50.json
Normal file
2445
app/schemas/io.github.wulkanowy.data.db.AppDatabase/50.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -55,7 +55,7 @@ import javax.inject.Singleton
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
companion object {
|
||||
const val VERSION_SCHEMA = 49
|
||||
const val VERSION_SCHEMA = 50
|
||||
|
||||
fun getMigrations(sharedPrefProvider: SharedPrefProvider, appInfo: AppInfo) = arrayOf(
|
||||
Migration2(),
|
||||
@ -102,7 +102,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Migration43(),
|
||||
Migration44(),
|
||||
Migration46(),
|
||||
Migration49()
|
||||
Migration49(),
|
||||
Migration50()
|
||||
)
|
||||
|
||||
fun newInstance(
|
||||
|
@ -8,6 +8,6 @@ import kotlinx.coroutines.flow.Flow
|
||||
@Dao
|
||||
interface MobileDeviceDao : BaseDao<MobileDevice> {
|
||||
|
||||
@Query("SELECT * FROM MobileDevices WHERE student_id = :userLoginId ORDER BY date DESC")
|
||||
@Query("SELECT * FROM MobileDevices WHERE user_login_id = :userLoginId ORDER BY date DESC")
|
||||
fun loadAll(userLoginId: Int): Flow<List<MobileDevice>>
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.time.Instant
|
||||
@Entity(tableName = "MobileDevices")
|
||||
data class MobileDevice(
|
||||
|
||||
@ColumnInfo(name = "student_id")
|
||||
@ColumnInfo(name = "user_login_id")
|
||||
val userLoginId: Int,
|
||||
|
||||
@ColumnInfo(name = "device_id")
|
||||
|
@ -0,0 +1,21 @@
|
||||
package io.github.wulkanowy.data.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration50 : Migration(49, 50) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS MobileDevices")
|
||||
database.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `MobileDevices` (
|
||||
`user_login_id` INTEGER NOT NULL,
|
||||
`device_id` INTEGER NOT NULL,
|
||||
`name` TEXT NOT NULL,
|
||||
`date` INTEGER NOT NULL,
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package io.github.wulkanowy.data.mappers
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.MobileDevice
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.pojos.MobileDeviceToken
|
||||
import io.github.wulkanowy.sdk.pojo.Device as SdkDevice
|
||||
import io.github.wulkanowy.sdk.pojo.Token as SdkToken
|
||||
|
||||
fun List<SdkDevice>.mapToEntities(semester: Semester) = map {
|
||||
fun List<SdkDevice>.mapToEntities(student: Student) = map {
|
||||
MobileDevice(
|
||||
userLoginId = semester.studentId,
|
||||
userLoginId = student.userLoginId,
|
||||
date = it.createDateZoned.toInstant(),
|
||||
deviceId = it.id,
|
||||
name = it.name
|
||||
|
@ -39,12 +39,12 @@ class MobileDeviceRepository @Inject constructor(
|
||||
val isExpired = refreshHelper.shouldBeRefreshed(getRefreshKey(cacheKey, student))
|
||||
it.isEmpty() || forceRefresh || isExpired
|
||||
},
|
||||
query = { mobileDb.loadAll(student.userLoginId.takeIf { it != 0 } ?: student.studentId) },
|
||||
query = { mobileDb.loadAll(student.userLoginId) },
|
||||
fetch = {
|
||||
sdk.init(student)
|
||||
.switchDiary(semester.diaryId, semester.kindergartenDiaryId, semester.schoolYear)
|
||||
.getRegisteredDevices()
|
||||
.mapToEntities(semester)
|
||||
.mapToEntities(student)
|
||||
},
|
||||
saveFetchResult = { old, new ->
|
||||
mobileDb.deleteAll(old uniqueSubtract new)
|
||||
|
@ -56,8 +56,8 @@ class MobileDeviceRepositoryTest {
|
||||
// prepare
|
||||
coEvery { sdk.getRegisteredDevices() } returns remoteList
|
||||
coEvery { mobileDeviceDb.loadAll(student.studentId) } returnsMany listOf(
|
||||
flowOf(remoteList.mapToEntities(semester)),
|
||||
flowOf(remoteList.mapToEntities(semester))
|
||||
flowOf(remoteList.mapToEntities(student)),
|
||||
flowOf(remoteList.mapToEntities(student))
|
||||
)
|
||||
coEvery { mobileDeviceDb.insertAll(any()) } returns listOf(1, 2, 3)
|
||||
coEvery { mobileDeviceDb.deleteAll(any()) } just Runs
|
||||
@ -79,9 +79,9 @@ class MobileDeviceRepositoryTest {
|
||||
// prepare
|
||||
coEvery { sdk.getRegisteredDevices() } returns remoteList
|
||||
coEvery { mobileDeviceDb.loadAll(1) } returnsMany listOf(
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(semester)),
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(semester)), // after fetch end before save result
|
||||
flowOf(remoteList.mapToEntities(semester))
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(student)),
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(student)), // after fetch end before save result
|
||||
flowOf(remoteList.mapToEntities(student))
|
||||
)
|
||||
coEvery { mobileDeviceDb.insertAll(any()) } returns listOf(1, 2, 3)
|
||||
coEvery { mobileDeviceDb.deleteAll(any()) } just Runs
|
||||
@ -96,7 +96,7 @@ class MobileDeviceRepositoryTest {
|
||||
coVerify { mobileDeviceDb.loadAll(1) }
|
||||
coVerify {
|
||||
mobileDeviceDb.insertAll(match {
|
||||
it.size == 1 && it[0] == remoteList.mapToEntities(semester)[1]
|
||||
it.size == 1 && it[0] == remoteList.mapToEntities(student)[1]
|
||||
})
|
||||
}
|
||||
coVerify { mobileDeviceDb.deleteAll(match { it.isEmpty() }) }
|
||||
@ -107,9 +107,9 @@ class MobileDeviceRepositoryTest {
|
||||
// prepare
|
||||
coEvery { sdk.getRegisteredDevices() } returns remoteList.dropLast(1)
|
||||
coEvery { mobileDeviceDb.loadAll(1) } returnsMany listOf(
|
||||
flowOf(remoteList.mapToEntities(semester)),
|
||||
flowOf(remoteList.mapToEntities(semester)), // after fetch end before save result
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(semester))
|
||||
flowOf(remoteList.mapToEntities(student)),
|
||||
flowOf(remoteList.mapToEntities(student)), // after fetch end before save result
|
||||
flowOf(remoteList.dropLast(1).mapToEntities(student))
|
||||
)
|
||||
coEvery { mobileDeviceDb.insertAll(any()) } returns listOf(1, 2, 3)
|
||||
coEvery { mobileDeviceDb.deleteAll(any()) } just Runs
|
||||
@ -125,7 +125,7 @@ class MobileDeviceRepositoryTest {
|
||||
coVerify { mobileDeviceDb.insertAll(match { it.isEmpty() }) }
|
||||
coVerify {
|
||||
mobileDeviceDb.deleteAll(match {
|
||||
it.size == 1 && it[0] == remoteList.mapToEntities(semester)[1]
|
||||
it.size == 1 && it[0] == remoteList.mapToEntities(student)[1]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user