forked from github/szkolny
[API/Vulcan] Fix teacher list subjects retrieving.
This commit is contained in:
parent
3b80adf355
commit
c39b5442c9
@ -4,10 +4,12 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import androidx.room.OnConflictStrategy
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_TEACHERS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_TEACHERS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.ext.DAY
|
||||
import pl.szczodrzynski.edziennik.ext.getString
|
||||
|
||||
@ -31,14 +33,26 @@ class VulcanHebeTeachers(
|
||||
val name = person.getString("Name")
|
||||
val surname = person.getString("Surname")
|
||||
val displayName = person.getString("DisplayName")
|
||||
val subjectName = person.getString("Description") ?: return@apiGetList
|
||||
val subjectName = person.getString("Description") ?: return@forEach
|
||||
|
||||
if (subjectName.isBlank()) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val teacher = data.getTeacherByFirstLast(
|
||||
name?.plus(" ")?.plus(surname) ?: displayName ?: return@forEach
|
||||
)
|
||||
|
||||
teacher.addSubject(data.getSubject(null, subjectName).id)
|
||||
when (subjectName) {
|
||||
"Pedagog" -> teacher.setTeacherType(Teacher.TYPE_PEDAGOGUE)
|
||||
else -> {
|
||||
val subjectId = data.getSubject(null, subjectName).id
|
||||
if (!teacher.subjects.contains(subjectId))
|
||||
teacher.addSubject(subjectId)
|
||||
}
|
||||
}
|
||||
}
|
||||
data.teacherOnConflictStrategy = OnConflictStrategy.REPLACE
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_TEACHERS, 2 * DAY)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_TEACHERS)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user