forked from github/szkolny
[APIv2/Librus] Move some code
This commit is contained in:
parent
e138ca6eab
commit
b32ebe4479
@ -31,10 +31,11 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
||||
?: return@forEach).toLong()
|
||||
val subject = announcement.getString("Subject") ?: ""
|
||||
val text = announcement.getString("Content") ?: ""
|
||||
val startDate = Date.fromY_m_d(announcement.getString("StartDate")
|
||||
?: return@forEach)
|
||||
val endDate = Date.fromY_m_d(announcement.getString("EndDate") ?: return@forEach)
|
||||
val startDate = Date.fromY_m_d(announcement.getString("StartDate"))
|
||||
val endDate = Date.fromY_m_d(announcement.getString("EndDate"))
|
||||
val teacherId = announcement.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||
val addedDate = Date.fromIso(announcement.getString("CreationDate"))
|
||||
val read = announcement.getBoolean("WasRead") ?: false
|
||||
|
||||
val announcementObject = Announcement(
|
||||
profileId,
|
||||
@ -46,10 +47,6 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
||||
teacherId
|
||||
)
|
||||
|
||||
val addedDate = Date.fromIso(announcement.getString("CreationDate")
|
||||
?: return@forEach)
|
||||
val read = announcement.getBoolean("WasRead") ?: false
|
||||
|
||||
data.announcementList.add(announcementObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
|
@ -27,22 +27,20 @@ class LibrusApiAttendances(override val data: DataLibrus,
|
||||
attendances?.forEach { attendanceEl ->
|
||||
val attendance = attendanceEl.asJsonObject
|
||||
|
||||
val id = Utils.strToInt((attendance.getString("Id") ?: return@forEach)
|
||||
.replace("[^\\d.]".toRegex(), "")).toLong()
|
||||
val teacherId = attendance.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||
val lessonNo = attendance.getInt("LessonNo") ?: return@forEach
|
||||
val startTime = data.lessonRanges.get(lessonNo).startTime
|
||||
val lessonDate = Date.fromY_m_d(attendance.getString("Date") ?: return@forEach)
|
||||
val lessonDate = Date.fromY_m_d(attendance.getString("Date"))
|
||||
val subjectId = data.lessonList.singleOrNull {
|
||||
it.weekDay == lessonDate.weekDay && it.startTime.value == startTime.value
|
||||
}?.subjectId ?: -1
|
||||
val semester = attendance.getInt("Semester") ?: return@forEach
|
||||
var type = attendance.getJsonObject("Type")?.getInt("Id") ?: return@forEach
|
||||
val attendanceType = data.attendanceTypes.get(type)
|
||||
val topic = attendanceType.second
|
||||
|
||||
val id = Utils.strToInt((attendance.getString("Id") ?: return@forEach)
|
||||
.replace("[^\\d.]".toRegex(), "")).toLong()
|
||||
|
||||
val subjectId = data.lessonList.singleOrNull {
|
||||
it.weekDay == lessonDate.weekDay && it.startTime.value == startTime.value
|
||||
}?.subjectId ?: -1
|
||||
|
||||
type = when(type) {
|
||||
1 -> Attendance.TYPE_ABSENT
|
||||
2 -> Attendance.TYPE_BELATED
|
||||
|
@ -46,7 +46,7 @@ class LibrusApiClasses(override val data: DataLibrus,
|
||||
?: return@apply)
|
||||
dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear")
|
||||
?: return@apply)
|
||||
if (unitId != null) putStudentData("unitId", unitId)
|
||||
unitId?.let { putStudentData("unitId", it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
val event = eventEl.asJsonObject
|
||||
|
||||
val id = event.getLong("Id") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(event.getString("Date") ?: return@forEach)
|
||||
val topic = event.getString("Content") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(event.getString("Date"))
|
||||
val topic = event.getString("Content") ?: ""
|
||||
val type = event.getJsonObject("Category")?.getInt("Id") ?: -1
|
||||
val teacherId = event.getJsonObject("CreatedBy")?.getLong("Id") ?: -1
|
||||
val subjectId = event.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||
@ -37,8 +37,8 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
|
||||
val lessonNo = event.getInt("LessonNo")
|
||||
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNo }
|
||||
val startTime = lessonRange?.startTime
|
||||
?: Time.fromH_m(event.getString("TimeFrom") ?: return@forEach)
|
||||
val startTime = lessonRange?.startTime ?: Time.fromH_m(event.getString("TimeFrom"))
|
||||
val addedDate = Date.fromIso(event.getString("AddDate"))
|
||||
|
||||
val eventObject = Event(
|
||||
profileId,
|
||||
@ -54,8 +54,6 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
teamId
|
||||
)
|
||||
|
||||
val addedDate = Date.fromIso(event.getString("AddDate") ?: return@forEach)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
|
@ -25,11 +25,12 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
val grade = gradeEl.asJsonObject
|
||||
|
||||
val id = grade.getLong("Id") ?: return@forEach
|
||||
val categoryId = grade.getJsonObject("Category")?.getLong("Id") ?: return@forEach
|
||||
val name = grade.getString("Grade") ?: return@forEach
|
||||
val categoryId = grade.getJsonObject("Category")?.getLong("Id") ?: -1
|
||||
val name = grade.getString("Grade") ?: ""
|
||||
val semester = grade.getInt("Semester") ?: return@forEach
|
||||
val teacherId = grade.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||
val subjectId = grade.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||
val addedDate = Date.fromIso(grade.getString("AddDate"))
|
||||
|
||||
val category = data.gradeCategories.singleOrNull { it.categoryId == categoryId }
|
||||
val categoryName = category?.text ?: ""
|
||||
@ -80,8 +81,6 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
gradeObject.isImprovement = true
|
||||
}
|
||||
|
||||
val addedDate = Date.fromIso(grade.get("AddDate").asString)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
|
@ -30,10 +30,10 @@ class LibrusApiHomework(override val data: DataLibrus,
|
||||
val homework = homeworkEl.asJsonObject
|
||||
|
||||
val id = homework.getLong("Id") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(homework.getString("DueDate") ?: return@forEach)
|
||||
val topic = (homework.getString("Topic") ?: "") + "\n" +
|
||||
(homework.getString("Text") ?: "")
|
||||
val eventDate = Date.fromY_m_d(homework.getString("DueDate"))
|
||||
val topic = homework.getString("Topic") + "\n" + homework.getString("Text")
|
||||
val teacherId = homework.getJsonObject("Teacher")?.getLong("Id") ?: -1
|
||||
val addedDate = Date.fromY_m_d(homework.getString("Date"))
|
||||
|
||||
val eventObject = Event(
|
||||
profileId,
|
||||
@ -49,8 +49,6 @@ class LibrusApiHomework(override val data: DataLibrus,
|
||||
-1
|
||||
)
|
||||
|
||||
val addedDate = Date.fromY_m_d(homework.getString("Date") ?: return@forEach)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
@ -49,6 +50,14 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
|
||||
)
|
||||
|
||||
data.teacherAbsenceList.add(teacherAbsenceObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_TEACHER_ABSENCE,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS, SYNC_ALWAYS)
|
||||
|
Loading…
Reference in New Issue
Block a user