[API/Podlasie] Add getting the lucky number.

This commit is contained in:
Kacper Ziubryniewicz 2020-05-13 19:56:41 +02:00
parent 4389dc9d79
commit 0ac8e1d9c1
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2020-5-13
*/
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.api
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
import pl.szczodrzynski.edziennik.utils.models.Date
class PodlasieApiLuckyNumber(val data: DataPodlasie, val luckyNumber: Int) {
init {
val luckyNumberObject = LuckyNumber(
profileId = data.profileId,
date = Date.getToday(),
number = luckyNumber
)
data.luckyNumberList.add(luckyNumberObject)
data.metadataList.add(
Metadata(
data.profileId,
Metadata.TYPE_LUCKY_NUMBER,
luckyNumberObject.date.value.toLong(),
true,
data.profile?.empty ?: false
))
}
}

View File

@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.ENDPOINT_PODLASIE_API_MAIN import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.ENDPOINT_PODLASIE_API_MAIN
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.PodlasieApi import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.PodlasieApi
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
import pl.szczodrzynski.edziennik.getInt
import pl.szczodrzynski.edziennik.getJsonArray import pl.szczodrzynski.edziennik.getJsonArray
class PodlasieApiMain(override val data: DataPodlasie, class PodlasieApiMain(override val data: DataPodlasie,
@ -23,6 +24,7 @@ class PodlasieApiMain(override val data: DataPodlasie,
apiGet(TAG, PODLASIE_API_USER_ENDPOINT) { json -> apiGet(TAG, PODLASIE_API_USER_ENDPOINT) { json ->
data.getTeam() // Save the class team when it doesn't exist. data.getTeam() // Save the class team when it doesn't exist.
json.getInt("LuckyNumber")?.let { PodlasieApiLuckyNumber(data, it) }
json.getJsonArray("Timetable")?.asJsonObjectList()?.let { PodlasieApiTimetable(data, it) } json.getJsonArray("Timetable")?.asJsonObjectList()?.let { PodlasieApiTimetable(data, it) }
json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) } json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) }
json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) } json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) }