forked from github/wulkanowy-mirror
Fix checking classId condition when is eduOne
This commit is contained in:
parent
8b9b1460ab
commit
6616a313e2
@ -5,6 +5,7 @@ import androidx.room.Insert
|
|||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -14,6 +15,11 @@ interface SemesterDao : BaseDao<Semester> {
|
|||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
suspend fun insertSemesters(items: List<Semester>): List<Long>
|
suspend fun insertSemesters(items: List<Semester>): List<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM Semesters WHERE (student_id = :studentId AND class_id = :classId) OR (student_id = :studentId AND class_id = 0)")
|
@Query("SELECT * FROM Semesters WHERE (student_id = :studentId AND class_id = :classId)")
|
||||||
suspend fun loadAll(studentId: Int, classId: Int): List<Semester>
|
suspend fun loadAll(studentId: Int, classId: Int): List<Semester>
|
||||||
|
|
||||||
|
suspend fun loadAll(student: Student): List<Semester> {
|
||||||
|
val classId = if (student.isEduOne == true) 0 else student.classId
|
||||||
|
return loadAll(student.studentId, classId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ abstract class StudentDao {
|
|||||||
abstract suspend fun loadAll(): List<Student>
|
abstract suspend fun loadAll(): List<Student>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM Students JOIN Semesters ON (Students.student_id = Semesters.student_id AND Students.class_id = Semesters.class_id) OR (Students.student_id = Semesters.student_id AND Semesters.class_id = 0)")
|
@Query("SELECT * FROM Students JOIN Semesters ON (Students.student_id = Semesters.student_id AND Students.class_id = Semesters.class_id) OR (Students.student_id = Semesters.student_id AND Semesters.class_id = 0 AND Students.is_edu_one = 1)")
|
||||||
abstract suspend fun loadStudentsWithSemesters(): Map<Student, List<Semester>>
|
abstract suspend fun loadStudentsWithSemesters(): Map<Student, List<Semester>>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM Students JOIN Semesters ON (Students.student_id = Semesters.student_id AND Students.class_id = Semesters.class_id) OR (Students.student_id = Semesters.student_id AND Semesters.class_id = 0) WHERE Students.id = :id")
|
@Query("SELECT * FROM Students JOIN Semesters ON (Students.student_id = Semesters.student_id AND Students.class_id = Semesters.class_id) OR (Students.student_id = Semesters.student_id AND Semesters.class_id = 0 AND Students.is_edu_one = 1) WHERE Students.id = :id")
|
||||||
abstract suspend fun loadStudentWithSemestersById(id: Long): Map<Student, List<Semester>>
|
abstract suspend fun loadStudentWithSemestersById(id: Long): Map<Student, List<Semester>>
|
||||||
|
|
||||||
@Query("UPDATE Students SET is_current = 1 WHERE id = :id")
|
@Query("UPDATE Students SET is_current = 1 WHERE id = :id")
|
||||||
|
@ -27,11 +27,11 @@ class SemesterRepository @Inject constructor(
|
|||||||
forceRefresh: Boolean = false,
|
forceRefresh: Boolean = false,
|
||||||
refreshOnNoCurrent: Boolean = false
|
refreshOnNoCurrent: Boolean = false
|
||||||
) = withContext(dispatchers.io) {
|
) = withContext(dispatchers.io) {
|
||||||
val semesters = semesterDb.loadAll(student.studentId, student.classId)
|
val semesters = semesterDb.loadAll(student)
|
||||||
|
|
||||||
if (isShouldFetch(student, semesters, forceRefresh, refreshOnNoCurrent)) {
|
if (isShouldFetch(student, semesters, forceRefresh, refreshOnNoCurrent)) {
|
||||||
refreshSemesters(student)
|
refreshSemesters(student)
|
||||||
semesterDb.loadAll(student.studentId, student.classId)
|
semesterDb.loadAll(student)
|
||||||
} else semesters
|
} else semesters
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class SemesterRepository @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val old = semesterDb.loadAll(student.studentId, student.classId)
|
val old = semesterDb.loadAll(student)
|
||||||
semesterDb.removeOldAndSaveNew(
|
semesterDb.removeOldAndSaveNew(
|
||||||
oldItems = old uniqueSubtract new,
|
oldItems = old uniqueSubtract new,
|
||||||
newItems = new uniqueSubtract old,
|
newItems = new uniqueSubtract old,
|
||||||
|
@ -123,7 +123,7 @@ class StudentRepository @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentStudentSemesters = semesterDb.loadAll(student.studentId, student.classId)
|
val currentStudentSemesters = semesterDb.loadAll(student)
|
||||||
if (currentStudentSemesters.isEmpty()) {
|
if (currentStudentSemesters.isEmpty()) {
|
||||||
Timber.d("Check isAuthorized: apply empty semesters workaround")
|
Timber.d("Check isAuthorized: apply empty semesters workaround")
|
||||||
semesterDb.insertSemesters(
|
semesterDb.insertSemesters(
|
||||||
@ -209,7 +209,7 @@ class StudentRepository @Inject constructor(
|
|||||||
|
|
||||||
studentDb.update(studentName)
|
studentDb.update(studentName)
|
||||||
semesterDb.removeOldAndSaveNew(
|
semesterDb.removeOldAndSaveNew(
|
||||||
oldItems = semesterDb.loadAll(student.studentId, semester.classId),
|
oldItems = semesterDb.loadAll(student),
|
||||||
newItems = newCurrentApiStudent.semesters.mapToEntities(newCurrentApiStudent.studentId)
|
newItems = newCurrentApiStudent.semesters.mapToEntities(newCurrentApiStudent.studentId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user