From 99ab9d586ff0210785839c6b51d571f3ec10fc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 2 Nov 2019 13:30:16 +0100 Subject: [PATCH] [APIv2] Revert changes in Data. --- .../edziennik/api/v2/models/Data.kt | 10 ---------- .../v2/vulcan/data/api/VulcanApiAttendance.kt | 7 +++++-- .../api/v2/vulcan/data/api/VulcanApiEvents.kt | 10 ++++++++-- .../v2/vulcan/data/api/VulcanApiMessagesInbox.kt | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt index 8e3865b8..6e5dce2e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt @@ -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 */ diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiAttendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiAttendance.kt index 20a8082f..1722cfed 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiAttendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiAttendance.kt @@ -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 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiEvents.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiEvents.kt index 37578e6f..d971118c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiEvents.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiEvents.kt @@ -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 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiMessagesInbox.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiMessagesInbox.kt index 50ba3411..ef1cacfe 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiMessagesInbox.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/api/VulcanApiMessagesInbox.kt @@ -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()} }