Remove classId from semester query when eduOne (#2509)

This commit is contained in:
Rafał Borcz 2024-03-26 19:02:35 +01:00 committed by GitHub
parent e1e276e1ea
commit 254719f22f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 27 deletions

View File

@ -195,7 +195,7 @@ ext {
}
dependencies {
implementation 'io.github.wulkanowy:sdk:2.5.4'
implementation 'io.github.wulkanowy:sdk:2.5.5-SNAPSHOT'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

View File

@ -5,6 +5,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student
import javax.inject.Singleton
@Singleton
@ -16,4 +17,15 @@ interface SemesterDao : BaseDao<Semester> {
@Query("SELECT * FROM Semesters WHERE student_id = :studentId AND class_id = :classId")
suspend fun loadAll(studentId: Int, classId: Int): List<Semester>
@Query("SELECT * FROM Semesters WHERE student_id = :studentId")
suspend fun loadAll(studentId: Int): List<Semester>
suspend fun loadAll(student: Student): List<Semester> {
return if (student.isEduOne == true) {
loadAll(student.studentId)
} else {
loadAll(student.studentId, student.classId)
}
}
}

View File

@ -27,11 +27,11 @@ class SemesterRepository @Inject constructor(
forceRefresh: Boolean = false,
refreshOnNoCurrent: Boolean = false
) = withContext(dispatchers.io) {
val semesters = semesterDb.loadAll(student.studentId, student.classId)
val semesters = semesterDb.loadAll(student)
if (isShouldFetch(student, semesters, forceRefresh, refreshOnNoCurrent)) {
refreshSemesters(student)
semesterDb.loadAll(student.studentId, student.classId)
semesterDb.loadAll(student)
} else semesters
}
@ -66,7 +66,7 @@ class SemesterRepository @Inject constructor(
if (new.isEmpty()) return Timber.i("Empty semester list!")
val old = semesterDb.loadAll(student.studentId, student.classId)
val old = semesterDb.loadAll(student)
semesterDb.removeOldAndSaveNew(
oldItems = old uniqueSubtract new,
newItems = new uniqueSubtract old,

View File

@ -123,7 +123,7 @@ class StudentRepository @Inject constructor(
return
}
val currentStudentSemesters = semesterDb.loadAll(student.studentId, student.classId)
val currentStudentSemesters = semesterDb.loadAll(student)
if (currentStudentSemesters.isEmpty()) {
Timber.d("Check isAuthorized: apply empty semesters workaround")
semesterDb.insertSemesters(
@ -209,7 +209,7 @@ class StudentRepository @Inject constructor(
studentDb.update(studentName)
semesterDb.removeOldAndSaveNew(
oldItems = semesterDb.loadAll(student.studentId, semester.classId),
oldItems = semesterDb.loadAll(student),
newItems = newCurrentApiStudent.semesters.mapToEntities(newCurrentApiStudent.studentId)
)
}

View File

@ -3,6 +3,7 @@ package io.github.wulkanowy.data.repositories
import io.github.wulkanowy.TestDispatchersProvider
import io.github.wulkanowy.createWulkanowySdkFactoryMock
import io.github.wulkanowy.data.db.dao.SemesterDao
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.mappers.mapToEntities
import io.github.wulkanowy.getSemesterEntity
import io.github.wulkanowy.getSemesterPojo
@ -50,7 +51,7 @@ class SemesterRepositoryTest {
getSemesterPojo(1, 2, now().minusMonths(3), now())
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns emptyList()
coEvery { semesterDb.loadAll(student) } returns emptyList()
coEvery { sdk.getSemesters() } returns semesters
coEvery { semesterDb.removeOldAndSaveNew(any(), any()) } just Runs
@ -76,12 +77,7 @@ class SemesterRepositoryTest {
getSemesterPojo(123, 2, now().minusMonths(3), now())
)
coEvery {
semesterDb.loadAll(
student.studentId,
student.classId
)
} returns badSemesters.mapToEntities(student.studentId)
coEvery { semesterDb.loadAll(student) } returns badSemesters.mapToEntities(student.studentId)
coEvery { sdk.getSemesters() } returns goodSemesters
coEvery { semesterDb.removeOldAndSaveNew(any(), any()) } just Runs
@ -103,7 +99,7 @@ class SemesterRepositoryTest {
getSemesterPojo(2, 3, now(), now().plusMonths(6)),
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returnsMany listOf(
coEvery { semesterDb.loadAll(any<Student>()) } returnsMany listOf(
badSemesters.mapToEntities(student.studentId),
badSemesters.mapToEntities(student.studentId),
goodSemesters.mapToEntities(student.studentId)
@ -125,7 +121,7 @@ class SemesterRepositoryTest {
getSemesterEntity(1, 2, now().minusMonths(6), now().minusMonths(1))
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
coEvery { semesterDb.loadAll(student) } returns semesters
val items = runBlocking { semesterRepository.getSemesters(student) }
assertEquals(2, items.size)
@ -138,7 +134,7 @@ class SemesterRepositoryTest {
getSemesterEntity(1, 2, now().minusMonths(3), now())
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
coEvery { semesterDb.loadAll(student) } returns semesters
val items = runBlocking { semesterRepository.getSemesters(student) }
assertEquals(2, items.size)
@ -151,7 +147,7 @@ class SemesterRepositoryTest {
getSemesterEntity(1, 2, now(), now())
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
coEvery { semesterDb.loadAll(student) } returns semesters
val items = runBlocking { semesterRepository.getSemesters(student) }
assertEquals(2, items.size)
@ -164,7 +160,7 @@ class SemesterRepositoryTest {
getSemesterPojo(1, 2, now().minusMonths(3), now())
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns emptyList()
coEvery { semesterDb.loadAll(student) } returns emptyList()
coEvery { sdk.getSemesters() } returns semesters
coEvery { semesterDb.removeOldAndSaveNew(any(), any()) } just Runs
@ -193,12 +189,7 @@ class SemesterRepositoryTest {
getSemesterPojo(2, 2, now().plusMonths(5), now().plusMonths(11)),
)
coEvery {
semesterDb.loadAll(
student.studentId,
student.classId
)
} returns semestersWithNoCurrent
coEvery { semesterDb.loadAll(student) } returns semestersWithNoCurrent
coEvery { sdk.getSemesters() } returns newSemesters
coEvery { semesterDb.removeOldAndSaveNew(any(), any()) } just Runs
@ -214,7 +205,7 @@ class SemesterRepositoryTest {
getSemesterEntity(1, 2, now().minusMonths(1), now().plusMonths(1))
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
coEvery { semesterDb.loadAll(student) } returns semesters
val items = semesterRepository.getSemesters(student, refreshOnNoCurrent = true)
assertEquals(2, items.size)
@ -227,14 +218,14 @@ class SemesterRepositoryTest {
getSemesterEntity(1, 1, now(), now())
)
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
coEvery { semesterDb.loadAll(student) } returns semesters
runBlocking { semesterRepository.getCurrentSemester(student) }
}
@Test(expected = RuntimeException::class)
fun getCurrentSemester_emptyList() {
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns emptyList()
coEvery { semesterDb.loadAll(student) } returns emptyList()
coEvery { sdk.getSemesters() } returns emptyList()
runBlocking { semesterRepository.getCurrentSemester(student) }