From c39b5442c90fe8f79cd297bc86de9db0239b3739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 31 Oct 2021 10:12:35 +0100 Subject: [PATCH] [API/Vulcan] Fix teacher list subjects retrieving. --- .../vulcan/data/hebe/VulcanHebeTeachers.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeTeachers.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeTeachers.kt index e9f209a3..cee25f58 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeTeachers.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeTeachers.kt @@ -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) }