mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 19:42:44 +01:00
Use db student id to distinguish reporting units and recipients (#1254)
This commit is contained in:
parent
464900d95b
commit
d0869b235a
@ -9,6 +9,6 @@ import javax.inject.Singleton
|
|||||||
@Dao
|
@Dao
|
||||||
interface RecipientDao : BaseDao<Recipient> {
|
interface RecipientDao : BaseDao<Recipient> {
|
||||||
|
|
||||||
@Query("SELECT * FROM Recipients WHERE student_id = :userLoginId AND unit_id = :unitId AND role = :role")
|
@Query("SELECT * FROM Recipients WHERE student_id = :studentId AND unit_id = :unitId AND role = :role")
|
||||||
suspend fun loadAll(userLoginId: Int, unitId: Int, role: Int): List<Recipient>
|
suspend fun loadAll(studentId: Int, unitId: Int, role: Int): List<Recipient>
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import java.io.Serializable
|
|||||||
data class Recipient(
|
data class Recipient(
|
||||||
|
|
||||||
@ColumnInfo(name = "student_id")
|
@ColumnInfo(name = "student_id")
|
||||||
val userLoginId: Int,
|
val studentId: Int,
|
||||||
|
|
||||||
@ColumnInfo(name = "real_id")
|
@ColumnInfo(name = "real_id")
|
||||||
val realId: String,
|
val realId: String,
|
||||||
|
@ -5,7 +5,7 @@ import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
|||||||
|
|
||||||
fun List<SdkRecipient>.mapToEntities(userLoginId: Int) = map {
|
fun List<SdkRecipient>.mapToEntities(userLoginId: Int) = map {
|
||||||
Recipient(
|
Recipient(
|
||||||
userLoginId = userLoginId,
|
studentId = userLoginId,
|
||||||
realId = it.id,
|
realId = it.id,
|
||||||
realName = it.name,
|
realName = it.name,
|
||||||
name = it.shortName,
|
name = it.shortName,
|
||||||
|
@ -6,7 +6,7 @@ import io.github.wulkanowy.sdk.pojo.ReportingUnit as SdkReportingUnit
|
|||||||
|
|
||||||
fun List<SdkReportingUnit>.mapToEntities(student: Student) = map {
|
fun List<SdkReportingUnit>.mapToEntities(student: Student) = map {
|
||||||
ReportingUnit(
|
ReportingUnit(
|
||||||
studentId = student.studentId,
|
studentId = student.id.toInt(),
|
||||||
unitId = it.id,
|
unitId = it.id,
|
||||||
roles = it.roles,
|
roles = it.roles,
|
||||||
senderId = it.senderId,
|
senderId = it.senderId,
|
||||||
|
@ -19,22 +19,22 @@ class RecipientRepository @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun refreshRecipients(student: Student, unit: ReportingUnit, role: Int) {
|
suspend fun refreshRecipients(student: Student, unit: ReportingUnit, role: Int) {
|
||||||
val new = sdk.init(student).getRecipients(unit.unitId, role).mapToEntities(unit.senderId)
|
val new = sdk.init(student).getRecipients(unit.unitId, role).mapToEntities(unit.studentId)
|
||||||
val old = recipientDb.loadAll(unit.senderId, unit.unitId, role)
|
val old = recipientDb.loadAll(unit.studentId, unit.unitId, role)
|
||||||
|
|
||||||
recipientDb.deleteAll(old uniqueSubtract new)
|
recipientDb.deleteAll(old uniqueSubtract new)
|
||||||
recipientDb.insertAll(new uniqueSubtract old)
|
recipientDb.insertAll(new uniqueSubtract old)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getRecipients(student: Student, unit: ReportingUnit, role: Int): List<Recipient> {
|
suspend fun getRecipients(student: Student, unit: ReportingUnit, role: Int): List<Recipient> {
|
||||||
return recipientDb.loadAll(unit.senderId, unit.unitId, role).ifEmpty {
|
return recipientDb.loadAll(unit.studentId, unit.unitId, role).ifEmpty {
|
||||||
refreshRecipients(student, unit, role)
|
refreshRecipients(student, unit, role)
|
||||||
|
|
||||||
recipientDb.loadAll(unit.senderId, unit.unitId, role)
|
recipientDb.loadAll(unit.studentId, unit.unitId, role)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getMessageRecipients(student: Student, message: Message): List<Recipient> {
|
suspend fun getMessageRecipients(student: Student, message: Message): List<Recipient> {
|
||||||
return sdk.init(student).getMessageRecipients(message.messageId, message.senderId).mapToEntities(student.userLoginId)
|
return sdk.init(student).getMessageRecipients(message.messageId, message.senderId).mapToEntities(student.studentId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,25 @@ class ReportingUnitRepository @Inject constructor(
|
|||||||
|
|
||||||
suspend fun refreshReportingUnits(student: Student) {
|
suspend fun refreshReportingUnits(student: Student) {
|
||||||
val new = sdk.init(student).getReportingUnits().mapToEntities(student)
|
val new = sdk.init(student).getReportingUnits().mapToEntities(student)
|
||||||
val old = reportingUnitDb.load(student.studentId)
|
val old = reportingUnitDb.load(student.id.toInt())
|
||||||
|
|
||||||
reportingUnitDb.deleteAll(old.uniqueSubtract(new))
|
reportingUnitDb.deleteAll(old.uniqueSubtract(new))
|
||||||
reportingUnitDb.insertAll(new.uniqueSubtract(old))
|
reportingUnitDb.insertAll(new.uniqueSubtract(old))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getReportingUnits(student: Student): List<ReportingUnit> {
|
suspend fun getReportingUnits(student: Student): List<ReportingUnit> {
|
||||||
return reportingUnitDb.load(student.studentId).ifEmpty {
|
return reportingUnitDb.load(student.id.toInt()).ifEmpty {
|
||||||
refreshReportingUnits(student)
|
refreshReportingUnits(student)
|
||||||
|
|
||||||
reportingUnitDb.load(student.studentId)
|
reportingUnitDb.load(student.id.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getReportingUnit(student: Student, unitId: Int): ReportingUnit? {
|
suspend fun getReportingUnit(student: Student, unitId: Int): ReportingUnit? {
|
||||||
return reportingUnitDb.loadOne(student.studentId, unitId) ?: run {
|
return reportingUnitDb.loadOne(student.id.toInt(), unitId) ?: run {
|
||||||
refreshReportingUnits(student)
|
refreshReportingUnits(student)
|
||||||
|
|
||||||
return reportingUnitDb.loadOne(student.studentId, unitId)
|
return reportingUnitDb.loadOne(student.id.toInt(), unitId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class RecipientLocalTest {
|
|||||||
coEvery { recipientDb.deleteAll(any()) } just Runs
|
coEvery { recipientDb.deleteAll(any()) } just Runs
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
val res = runBlocking { recipientRepository.getRecipients(student, ReportingUnit(1, 123, "", 4, "", listOf()), 7) }
|
val res = runBlocking { recipientRepository.getRecipients(student, ReportingUnit(4, 123, "", 4, "", listOf()), 7) }
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
assertEquals(3, res.size)
|
assertEquals(3, res.size)
|
||||||
@ -73,7 +73,7 @@ class RecipientLocalTest {
|
|||||||
coEvery { recipientDb.deleteAll(any()) } just Runs
|
coEvery { recipientDb.deleteAll(any()) } just Runs
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
val res = runBlocking { recipientRepository.getRecipients(student, ReportingUnit(1, 123, "", 4, "", listOf()), 7) }
|
val res = runBlocking { recipientRepository.getRecipients(student, ReportingUnit(4, 123, "", 4, "", listOf()), 7) }
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
assertEquals(3, res.size)
|
assertEquals(3, res.size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user