[API/Librus] Fix LibrusApiTeacherFreeDays. (#123)

* [API/Librus] Remove LibrusApiTeacherFreeDayTypes

* [API/Librus] Fix LibrusApiTeacherFreeDay

* [API/Librus] LibrusApiTeacherFreeDay: Clean up values of unused variables

* [API/Librus] LibrusApiTeacherFreeDay: Remove unnecessary variables

* [API/Librus] LibrusApiTeacherFreeDay: Assign null to 'name' object
This commit is contained in:
B.O.S.S 2021-12-10 21:48:11 +01:00 committed by GitHub
parent 2b104e6463
commit aa06868a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 55 deletions

View File

@ -182,10 +182,6 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
data.startProgress(R.string.edziennik_progress_endpoint_pt_meetings) data.startProgress(R.string.edziennik_progress_endpoint_pt_meetings)
LibrusApiPtMeetings(data, lastSync, onSuccess) LibrusApiPtMeetings(data, lastSync, onSuccess)
} }
ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES -> {
data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_day_types)
LibrusApiTeacherFreeDayTypes(data, lastSync, onSuccess)
}
ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS -> { ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS -> {
data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days) data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days)
LibrusApiTeacherFreeDays(data, lastSync, onSuccess) LibrusApiTeacherFreeDays(data, lastSync, onSuccess)

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-10-19
*/
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
import pl.szczodrzynski.edziennik.data.db.entity.TeacherAbsenceType
import pl.szczodrzynski.edziennik.ext.*
class LibrusApiTeacherFreeDayTypes(override val data: DataLibrus,
override val lastSync: Long?,
val onSuccess: (endpointId: Int) -> Unit
) : LibrusApi(data, lastSync) {
companion object {
const val TAG = "LibrusApiTeacherFreeDayTypes"
}
init {
apiGet(TAG, "TeacherFreeDays/Types") { json ->
val teacherAbsenceTypes = json.getJsonArray("Types")?.asJsonObjectList()
teacherAbsenceTypes?.forEach { teacherAbsenceType ->
val id = teacherAbsenceType.getLong("Id") ?: return@forEach
val name = teacherAbsenceType.getString("Name") ?: return@forEach
val teacherAbsenceTypeObject = TeacherAbsenceType(
profileId,
id,
name
)
data.teacherAbsenceTypes.put(id, teacherAbsenceTypeObject)
}
data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES, 7 * DAY)
onSuccess(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES)
}
}
}

View File

@ -36,22 +36,18 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
val id = teacherAbsence.getLong("Id") ?: return@forEach val id = teacherAbsence.getLong("Id") ?: return@forEach
val teacherId = teacherAbsence.getJsonObject("Teacher")?.getLong("Id") val teacherId = teacherAbsence.getJsonObject("Teacher")?.getLong("Id")
?: return@forEach ?: return@forEach
val type = teacherAbsence.getJsonObject("Type").getLong("Id") ?: return@forEach
val name = data.teacherAbsenceTypes.singleOrNull { it.id == type }?.name
val dateFrom = Date.fromY_m_d(teacherAbsence.getString("DateFrom")) val dateFrom = Date.fromY_m_d(teacherAbsence.getString("DateFrom"))
val dateTo = Date.fromY_m_d(teacherAbsence.getString("DateTo")) val dateTo = Date.fromY_m_d(teacherAbsence.getString("DateTo"))
val timeFrom = teacherAbsence.getString("TimeFrom")?.let { Time.fromH_m_s(it) }
val timeTo = teacherAbsence.getString("TimeTo")?.let { Time.fromH_m_s(it) }
val teacherAbsenceObject = TeacherAbsence( val teacherAbsenceObject = TeacherAbsence(
profileId = profileId, profileId = profileId,
id = id, id = id,
type = type, type = -1L,
name = name, name = null,
dateFrom = dateFrom, dateFrom = dateFrom,
dateTo = dateTo, dateTo = dateTo,
timeFrom = timeFrom, timeFrom = null,
timeTo = timeTo, timeTo = null,
teacherId = teacherId teacherId = teacherId
) )