From 70de47408a2cb895891425d615c940cfc8df9732 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Wed, 25 Dec 2019 02:17:20 +0100 Subject: [PATCH] [API/Edudziennik] Add getting teachers and *change endpoint IDs.* --- .../edziennik/data/api/Regexes.kt | 4 +++ .../edziennik/edudziennik/DataEdudziennik.kt | 9 ++---- .../edudziennik/EdudziennikFeatures.kt | 15 ++++++--- .../edudziennik/data/EdudziennikData.kt | 12 ++++--- .../data/web/EdudziennikWebTeachers.kt | 32 +++++++++++++++++++ 5 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTeachers.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt index a4f20f9f..8ca1af0b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt @@ -138,4 +138,8 @@ object Regexes { val EDUDZIENNIK_CLASS_DETAIL_NAME by lazy { """(.*?)""".toRegex(DOT_MATCHES_ALL) } + + val EDUDZIENNIK_TEACHERS by lazy { + """
.*?

(.+?) (.+?)

""".toRegex(DOT_MATCHES_ALL) + } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt index 121d5476..26dbf32f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt @@ -92,18 +92,15 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat val schoolEndpoint: String get() = "Schools/$schoolId/" - val schoolClassEndpoint: String - get() = "Schools/$classId/" - val studentAndClassEndpoint: String get() = "Students/$studentId/Klass/$classId/" - val courseEndpoint: String - get() = "Course/$studentId/" - val timetableEndpoint: String get() = "Plan/$studentId/" + val studentAndTeacherClassEndpoint: String + get() = "Students/$studentId/Teachers/$classId/" + fun getSubject(longId: String, name: String): Subject { val id = longId.crc32() return subjectList.singleOrNull { it.id == id } ?: run { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/EdudziennikFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/EdudziennikFeatures.kt index f98192c6..9791a983 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/EdudziennikFeatures.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/EdudziennikFeatures.kt @@ -8,17 +8,22 @@ import pl.szczodrzynski.edziennik.data.api.* import pl.szczodrzynski.edziennik.data.api.models.Feature const val ENDPOINT_EDUDZIENNIK_WEB_START = 1000 -const val ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE = 1001 -const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1002 -const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1003 -const val ENDPOINT_EDUDZIENNIK_WEB_GRADES = 1004 -const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1010 +const val ENDPOINT_EDUDZIENNIK_WEB_TEACHERS = 1001 +const val ENDPOINT_EDUDZIENNIK_WEB_GRADES = 1011 +const val ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE = 1012 +const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1013 +const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1014 +const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1030 val EdudziennikFeatures = listOf( Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_STUDENT_INFO, listOf( ENDPOINT_EDUDZIENNIK_WEB_START to LOGIN_METHOD_EDUDZIENNIK_WEB ), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)), + Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TEACHERS, listOf( + ENDPOINT_EDUDZIENNIK_WEB_TEACHERS to LOGIN_METHOD_EDUDZIENNIK_WEB + ), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)), + Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TIMETABLE, listOf( ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE to LOGIN_METHOD_EDUDZIENNIK_WEB ), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)), diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/EdudziennikData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/EdudziennikData.kt index 1d94b459..d799d115 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/EdudziennikData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/EdudziennikData.kt @@ -40,6 +40,14 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_data) EdudziennikWebStart(data, onSuccess) } + ENDPOINT_EDUDZIENNIK_WEB_TEACHERS -> { + data.startProgress(R.string.edziennik_progress_endpoint_teachers) + EdudziennikWebTeachers(data, onSuccess) + } + ENDPOINT_EDUDZIENNIK_WEB_GRADES -> { + data.startProgress(R.string.edziennik_progress_endpoint_grades) + EdudziennikWebGrades(data, onSuccess) + } ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE -> { data.startProgress(R.string.edziennik_progress_endpoint_timetable) EdudziennikWebTimetable(data, onSuccess) @@ -52,10 +60,6 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_attendance) EdudziennikWebAttendance(data, onSuccess) } - ENDPOINT_EDUDZIENNIK_WEB_GRADES -> { - data.startProgress(R.string.edziennik_progress_endpoint_grades) - EdudziennikWebGrades(data, onSuccess) - } ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> { data.startProgress(R.string.edziennik_progress_endpoint_lucky_number) EdudziennikWebLuckyNumber(data, onSuccess) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTeachers.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTeachers.kt new file mode 100644 index 00000000..e82ab7dc --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTeachers.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2019-12-25 + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web + +import pl.szczodrzynski.edziennik.MONTH +import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_TEACHERS +import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik +import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_TEACHERS +import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb +import pl.szczodrzynski.edziennik.get + +class EdudziennikWebTeachers(override val data: DataEdudziennik, + val onSuccess: () -> Unit) : EdudziennikWeb(data) { + companion object { + private const val TAG = "EdudziennikWebTeachers" + } + + init { data.profile?.also { profile -> + webGet(TAG, data.studentAndTeacherClassEndpoint + "grid") { text -> + EDUDZIENNIK_TEACHERS.findAll(text).forEach { + val lastName = it[1].trim() + val firstName = it[2].trim() + data.getTeacher(firstName, lastName) + } + + data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_TEACHERS, MONTH) + onSuccess() + } + } ?: onSuccess() } +}