mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[APIv2/Librus] Add Virtual classes, Users, Subjects.
This commit is contained in:
parent
7822810b91
commit
36c810fdbe
@ -210,4 +210,9 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName }
|
||||
set(value) { profile?.putStudentData("schoolName", value) ?: return; mSchoolName = value }
|
||||
|
||||
private var mUnitId: Long? = null
|
||||
var unitId: Long
|
||||
get() { mUnitId = mUnitId ?: profile?.getStudentData("unitId", 0L); return mUnitId ?: 0L }
|
||||
set(value) { profile?.putStudentData("unitId", value) ?: return; mUnitId = value }
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,14 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.DAY
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_CLASSES
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class LibrusApiClasses(override val data: DataLibrus,
|
||||
@ -37,7 +40,7 @@ class LibrusApiClasses(override val data: DataLibrus,
|
||||
|
||||
data.teamList.put(id, teamObject)
|
||||
|
||||
val unitId = studentClass.getJsonObject("Unit").getLong("Id")
|
||||
data.unitId = studentClass.getJsonObject("Unit").getLong("Id") ?: 0L
|
||||
|
||||
profile?.apply {
|
||||
dateSemester1Start = Date.fromY_m_d(studentClass.getString("BeginSchoolYear")
|
||||
@ -46,7 +49,6 @@ class LibrusApiClasses(override val data: DataLibrus,
|
||||
?: return@apply)
|
||||
dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear")
|
||||
?: return@apply)
|
||||
unitId?.let { putStudentData("unitId", it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.DAY
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_SUBJECTS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class LibrusApiSubjects(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiSubjects"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "Subjects") { json ->
|
||||
json.getJsonArray("Subjects")?.forEach { subjectEl ->
|
||||
val subject = subjectEl.asJsonObject
|
||||
|
||||
val id = subject.getLong("Id") ?: return@forEach
|
||||
val longName = subject.getString("Name") ?: ""
|
||||
val shortName = subject.getString("Short") ?: ""
|
||||
|
||||
data.subjectList.put(id, Subject(profileId, id, longName, shortName))
|
||||
}
|
||||
|
||||
data.subjectList.put(1, Subject(profileId, 1, "Zachowanie", "zach"))
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_SUBJECTS, 4*DAY)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_USERS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||
|
||||
class LibrusApiUsers(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiUsers"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "Users") { json ->
|
||||
json.getJsonArray("Users")?.forEach { userEl ->
|
||||
val user = userEl.asJsonObject
|
||||
|
||||
val id = user.getLong("Id") ?: return@forEach
|
||||
val firstName = user.getString("FirstName")?.fixWhiteSpaces() ?: ""
|
||||
val lastName = user.getString("LastName")?.fixWhiteSpaces() ?: ""
|
||||
|
||||
data.teacherList.put(id, Teacher(profileId, id, firstName, lastName))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_USERS, 4*DAY)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||
|
||||
class LibrusApiVirtualClasses(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiVirtualClasses"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "VirtualClasses") { json ->
|
||||
json.getJsonArray("VirtualClasses")?.forEach { virtualClassEl ->
|
||||
val virtualClass = virtualClassEl.asJsonObject
|
||||
|
||||
val id = virtualClass.getLong("Id") ?: return@forEach
|
||||
val name = virtualClass.getString("Name") ?: ""
|
||||
val teacherId = virtualClass.getJsonObject("Teacher")?.getLong("Id") ?: -1
|
||||
val code = "${data.schoolName}:$name"
|
||||
|
||||
data.teamList.put(id, Team(profileId, id, name, 2, code, teacherId))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES, 4*DAY)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user