io.github.wulkanowy.sdk.hebe.repository.StudentRepository.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-hebe Show documentation
Show all versions of sdk-hebe Show documentation
Unified way of retrieving data from the UONET+ register through mobile api and scraping api
package io.github.wulkanowy.sdk.hebe.repository
import io.github.wulkanowy.sdk.hebe.getEnvelopeOrThrowError
import io.github.wulkanowy.sdk.hebe.models.Exam
import io.github.wulkanowy.sdk.hebe.models.Grade
import io.github.wulkanowy.sdk.hebe.models.GradeAverage
import io.github.wulkanowy.sdk.hebe.models.GradeSummary
import io.github.wulkanowy.sdk.hebe.service.StudentService
import java.time.LocalDate
import java.time.format.DateTimeFormatter
internal class StudentRepository(private val studentService: StudentService) {
suspend fun getGrades(pupilId: Int, periodId: Int): List {
return studentService.getGrades(
createQueryMap(pupilId = pupilId, periodId = periodId),
).getEnvelopeOrThrowError().orEmpty()
}
suspend fun getGradesSummary(pupilId: Int, periodId: Int): List {
return studentService.getGradesSummary(
createQueryMap(pupilId = pupilId, periodId = periodId),
).getEnvelopeOrThrowError().orEmpty()
}
suspend fun getGradesAverage(pupilId: Int, periodId: Int): List {
return studentService.getGradesAverage(
createQueryMap(pupilId = pupilId, periodId = periodId),
).getEnvelopeOrThrowError().orEmpty()
}
suspend fun getExams(pupilId: Int, startDate: LocalDate, endDate: LocalDate): List {
return studentService.getExams(
createQueryMap(pupilId = pupilId, dateFrom = startDate),
).getEnvelopeOrThrowError().orEmpty().filter {
it.deadline.date in startDate..endDate
}
}
private fun createQueryMap(
pupilId: Int,
periodId: Int? = null,
dateFrom: LocalDate? = null,
dateTo: LocalDate? = null,
): Map = mapOf(
"pupilId" to pupilId,
"periodId" to periodId,
"lastSyncDate" to "1970-01-01 01:00:00",
"lastId" to Int.MIN_VALUE,
"pageSize" to 500,
"dateFrom" to dateFrom?.format(DateTimeFormatter.ISO_DATE),
"dateTo" to dateTo?.format(DateTimeFormatter.ISO_DATE),
).filterValues { it != null }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy