forked from github/szkolny
[API/Podlasie] Add getting teachers.
This commit is contained in:
parent
031cc05209
commit
795317f13f
@ -77,7 +77,7 @@ class DataPodlasie(app: App, profile: Profile?, loginStore: LoginStore) : Data(a
|
||||
set(value) { profile?.putStudentData("currentSemester", value) ?: return; mCurrentSemester = value }
|
||||
|
||||
val schoolShortName: String?
|
||||
get() = studentLogin?.replace(".podlaskie.pl", "")
|
||||
get() = studentLogin?.split('@')?.get(1)?.replace(".podlaskie.pl", "")
|
||||
|
||||
val loginShort: String?
|
||||
get() = studentLogin?.split('@')?.get(0)
|
||||
@ -93,8 +93,8 @@ class DataPodlasie(app: App, profile: Profile?, loginStore: LoginStore) : Data(a
|
||||
|
||||
fun getTeacher(firstName: String, lastName: String): Teacher {
|
||||
val name = "$firstName $lastName".fixName()
|
||||
val id = name.crc32()
|
||||
return teacherList.singleOrNull { it.id == id } ?: run {
|
||||
return teacherList.singleOrNull { it.fullName == name } ?: run {
|
||||
val id = name.crc32()
|
||||
val teacher = Teacher(profileId, id, firstName, lastName)
|
||||
teacherList.put(id, teacher)
|
||||
teacher
|
||||
|
@ -25,6 +25,7 @@ class PodlasieApiMain(override val data: DataPodlasie,
|
||||
data.getTeam() // Save the class team when it doesn't exist.
|
||||
|
||||
json.getInt("LuckyNumber")?.let { PodlasieApiLuckyNumber(data, it) }
|
||||
json.getJsonArray("Teacher")?.asJsonObjectList()?.let { PodlasieApiTeachers(data, it) }
|
||||
json.getJsonArray("Timetable")?.asJsonObjectList()?.let { PodlasieApiTimetable(data, it) }
|
||||
json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) }
|
||||
json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) }
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-5-13
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.api
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class PodlasieApiTeachers(val data: DataPodlasie, val rows: List<JsonObject>) {
|
||||
init {
|
||||
rows.forEach { teacher ->
|
||||
val id = teacher.getLong("ExternalId") ?: return@forEach
|
||||
val firstName = teacher.getString("FirstName") ?: return@forEach
|
||||
val lastName = teacher.getString("LastName") ?: return@forEach
|
||||
val isEducator = teacher.getInt("Educator") == 1
|
||||
|
||||
val teacherObject = Teacher(
|
||||
profileId = data.profileId,
|
||||
id = id,
|
||||
name = firstName,
|
||||
surname = lastName,
|
||||
loginId = null
|
||||
)
|
||||
|
||||
data.teacherList.put(id, teacherObject)
|
||||
|
||||
val teamClass = data.teamClass
|
||||
if (isEducator && teamClass != null) {
|
||||
data.teamList.put(teamClass.id, teamClass.apply {
|
||||
teacherId = id
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user