[APIv2] Revert changes in Data.

This commit is contained in:
Kuba Szczodrzyński 2019-11-02 13:30:16 +01:00
parent 33c009befe
commit 99ab9d586f
4 changed files with 25 additions and 18 deletions

View File

@ -60,16 +60,6 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
val profileId
get() = profile?.id ?: -1
val syncStartDate: Date
get() = when (profile?.empty) {
true -> profile.getSemesterStart(profile.currentSemester)
else -> Date.getToday().stepForward(0, -1, 0)
}
val syncEndDate: Date
get() = profile?.getSemesterEnd(profile.currentSemester)
?: Date.getToday().stepForward(0, 1, 0)
/**
* A callback passed to all [Feature]s and [LoginMethod]s
*/

View File

@ -22,9 +22,12 @@ class VulcanApiAttendance(override val data: DataVulcan, val onSuccess: () -> Un
data.db.attendanceTypeDao().getAllNow(profileId).toSparseArray(data.attendanceTypes) { it.id }
}
val startDate: String = profile.getSemesterStart(profile.currentSemester).stringY_m_d
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
apiGet(TAG, VULCAN_API_ENDPOINT_ATTENDANCE, parameters = mapOf(
"DataPoczatkowa" to data.syncStartDate.stringY_m_d,
"DataKoncowa" to data.syncEndDate.stringY_m_d,
"DataPoczatkowa" to startDate,
"DataKoncowa" to endDate,
"IdOddzial" to data.studentClassId,
"IdUczen" to data.studentId,
"IdOkresKlasyfikacyjny" to data.studentSemesterId

View File

@ -26,13 +26,19 @@ class VulcanApiEvents(override val data: DataVulcan, private val isHomework: Boo
init { data.profile?.also { profile ->
val startDate: String = when (profile.empty) {
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
}
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
val endpoint = when (isHomework) {
true -> VULCAN_API_ENDPOINT_HOMEWORK
else -> VULCAN_API_ENDPOINT_EVENTS
}
apiGet(TAG, endpoint, parameters = mapOf(
"DataPoczatkowa" to data.syncStartDate.stringY_m_d,
"DataKoncowa" to data.syncEndDate.stringY_m_d,
"DataPoczatkowa" to startDate,
"DataKoncowa" to endDate,
"IdOddzial" to data.studentClassId,
"IdUczen" to data.studentId,
"IdOkresKlasyfikacyjny" to data.studentSemesterId

View File

@ -13,16 +13,24 @@ import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
import pl.szczodrzynski.edziennik.utils.models.Date
class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
companion object {
const val TAG = "VulcanApiMessagesInbox"
}
init {
init { data.profile?.also { profile ->
val startDate: String = when (profile.empty) {
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
}
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_RECEIVED, parameters = mapOf(
"DataPoczatkowa" to data.syncStartDate.inUnix,
"DataKoncowa" to data.syncEndDate.inUnix,
"DataPoczatkowa" to startDate,
"DataKoncowa" to endDate,
"LoginId" to data.studentLoginId,
"IdUczen" to data.studentId
)) { json, _ ->
@ -71,5 +79,5 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () ->
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
onSuccess()
}
}
} ?: onSuccess()}
}