From 4a65a5b19236d4cdb53a9d804cf8e91af7c4749e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 21 Apr 2024 23:51:34 +0200 Subject: [PATCH] Migrate away from userLoginId to studentId due to vulcan last changes --- .../java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt | 4 ++-- .../io/github/wulkanowy/data/db/dao/SchoolAnnouncementDao.kt | 4 ++-- .../java/io/github/wulkanowy/data/db/entities/MobileDevice.kt | 4 ++-- .../github/wulkanowy/data/db/entities/SchoolAnnouncement.kt | 4 ++-- .../main/java/io/github/wulkanowy/data/db/entities/Student.kt | 1 + .../wulkanowy/data/mappers/DirectorInformationMapper.kt | 4 ++-- .../io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt | 2 +- .../wulkanowy/data/repositories/MobileDeviceRepository.kt | 2 +- .../data/repositories/SchoolAnnouncementRepository.kt | 4 ++-- .../ui/modules/debug/notification/mock/schoolAnnouncement.kt | 2 +- app/src/main/java/io/github/wulkanowy/utils/RefreshUtils.kt | 2 +- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt b/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt index 96382cc1..5ddb4dd0 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt @@ -8,6 +8,6 @@ import kotlinx.coroutines.flow.Flow @Dao interface MobileDeviceDao : BaseDao { - @Query("SELECT * FROM MobileDevices WHERE user_login_id = :userLoginId ORDER BY date DESC") - fun loadAll(userLoginId: Int): Flow> + @Query("SELECT * FROM MobileDevices WHERE user_login_id = :studentId ORDER BY date DESC") + fun loadAll(studentId: Int): Flow> } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/SchoolAnnouncementDao.kt b/app/src/main/java/io/github/wulkanowy/data/db/dao/SchoolAnnouncementDao.kt index c32e4aba..64d49bce 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/SchoolAnnouncementDao.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/SchoolAnnouncementDao.kt @@ -10,6 +10,6 @@ import javax.inject.Singleton @Singleton interface SchoolAnnouncementDao : BaseDao { - @Query("SELECT * FROM SchoolAnnouncements WHERE user_login_id = :userLoginId ORDER BY date DESC") - fun loadAll(userLoginId: Int): Flow> + @Query("SELECT * FROM SchoolAnnouncements WHERE user_login_id = :studentId ORDER BY date DESC") + fun loadAll(studentId: Int): Flow> } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt b/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt index 89b04ccc..44e90064 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt @@ -9,8 +9,8 @@ import java.time.Instant @Entity(tableName = "MobileDevices") data class MobileDevice( - @ColumnInfo(name = "user_login_id") - val userLoginId: Int, + @ColumnInfo(name = "user_login_id") // todo: change column name + val studentId: Int, @ColumnInfo(name = "device_id") val deviceId: Int, diff --git a/app/src/main/java/io/github/wulkanowy/data/db/entities/SchoolAnnouncement.kt b/app/src/main/java/io/github/wulkanowy/data/db/entities/SchoolAnnouncement.kt index ac096b02..814a3c8d 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/entities/SchoolAnnouncement.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/entities/SchoolAnnouncement.kt @@ -9,8 +9,8 @@ import java.time.LocalDate @Entity(tableName = "SchoolAnnouncements") data class SchoolAnnouncement( - @ColumnInfo(name = "user_login_id") - val userLoginId: Int, + @ColumnInfo(name = "user_login_id") // todo: change column name + val studentId: Int, val date: LocalDate, diff --git a/app/src/main/java/io/github/wulkanowy/data/db/entities/Student.kt b/app/src/main/java/io/github/wulkanowy/data/db/entities/Student.kt index dbaa573c..0300506a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/entities/Student.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/entities/Student.kt @@ -49,6 +49,7 @@ data class Student( @ColumnInfo(name = "student_id") val studentId: Int, + @Deprecated("not available in VULCAN anymore") @ColumnInfo(name = "user_login_id") val userLoginId: Int, diff --git a/app/src/main/java/io/github/wulkanowy/data/mappers/DirectorInformationMapper.kt b/app/src/main/java/io/github/wulkanowy/data/mappers/DirectorInformationMapper.kt index 85b37afc..1a84a6a5 100644 --- a/app/src/main/java/io/github/wulkanowy/data/mappers/DirectorInformationMapper.kt +++ b/app/src/main/java/io/github/wulkanowy/data/mappers/DirectorInformationMapper.kt @@ -8,7 +8,7 @@ import io.github.wulkanowy.sdk.pojo.LastAnnouncement as SdkLastAnnouncement @JvmName("mapDirectorInformationToEntities") fun List.mapToEntities(student: Student) = map { SchoolAnnouncement( - userLoginId = student.userLoginId, + studentId = student.studentId, date = it.date, subject = it.subject, content = it.content, @@ -19,7 +19,7 @@ fun List.mapToEntities(student: Student) = map { @JvmName("mapLastAnnouncementsToEntities") fun List.mapToEntities(student: Student) = map { SchoolAnnouncement( - userLoginId = student.userLoginId, + studentId = student.studentId, date = it.date, subject = it.subject, content = it.content, diff --git a/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt b/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt index 1f4178fa..3818f01a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt +++ b/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt @@ -8,7 +8,7 @@ import io.github.wulkanowy.sdk.pojo.Token as SdkToken fun List.mapToEntities(student: Student) = map { MobileDevice( - userLoginId = student.userLoginId, + studentId = student.studentId, date = it.createDate.toInstant(), deviceId = it.id, name = it.name diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt index 19466554..1303d0e7 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt @@ -38,7 +38,7 @@ class MobileDeviceRepository @Inject constructor( val isExpired = refreshHelper.shouldBeRefreshed(getRefreshKey(cacheKey, student)) it.isEmpty() || forceRefresh || isExpired }, - query = { mobileDb.loadAll(student.userLoginId) }, + query = { mobileDb.loadAll(student.studentId) }, fetch = { wulkanowySdkFactory.create(student, semester) .getRegisteredDevices() diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/SchoolAnnouncementRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/SchoolAnnouncementRepository.kt index 6a04ce75..78d95699 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/SchoolAnnouncementRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/SchoolAnnouncementRepository.kt @@ -37,7 +37,7 @@ class SchoolAnnouncementRepository @Inject constructor( it.isEmpty() || forceRefresh || isExpired }, query = { - schoolAnnouncementDb.loadAll(student.userLoginId) + schoolAnnouncementDb.loadAll(student.studentId) }, fetch = { val sdk = wulkanowySdkFactory.create(student) @@ -57,7 +57,7 @@ class SchoolAnnouncementRepository @Inject constructor( ) fun getSchoolAnnouncementFromDatabase(student: Student): Flow> { - return schoolAnnouncementDb.loadAll(student.userLoginId) + return schoolAnnouncementDb.loadAll(student.studentId) } suspend fun updateSchoolAnnouncement(schoolAnnouncement: List) = diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/schoolAnnouncement.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/schoolAnnouncement.kt index e2dc5cd8..9b21f08e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/schoolAnnouncement.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/schoolAnnouncement.kt @@ -19,6 +19,6 @@ val debugSchoolAnnouncementItems = listOf( private fun generateAnnouncement(subject: String, content: String) = SchoolAnnouncement( subject = subject, content = content, - userLoginId = 0, + studentId = 0, date = LocalDate.now() ) diff --git a/app/src/main/java/io/github/wulkanowy/utils/RefreshUtils.kt b/app/src/main/java/io/github/wulkanowy/utils/RefreshUtils.kt index 72129751..e43654b8 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/RefreshUtils.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/RefreshUtils.kt @@ -23,7 +23,7 @@ fun getRefreshKey(name: String, semester: Semester): String { } fun getRefreshKey(name: String, student: Student): String { - return "${name}_${student.userLoginId}" + return "${name}_${student.studentId}" } fun getRefreshKey(name: String, mailbox: Mailbox?, folder: MessageFolder): String {