Add missing semester fetch impl via eduOne

This commit is contained in:
Mikołaj Pich 2024-03-20 00:31:51 +01:00
parent 2583e044e7
commit 1b6e840917
No known key found for this signature in database
2 changed files with 27 additions and 1 deletions

View file

@ -335,7 +335,10 @@ class Scrapper {
}
}
suspend fun getSemesters(): List<Semester> = studentStart.getSemesters()
suspend fun getSemesters(): List<Semester> = when (isEduOne) {
true -> studentPlus.getSemesters(studentId, diaryId, unitId)
else -> studentStart.getSemesters()
}
suspend fun getCurrentStudent(): RegisterStudent? {
return when (isEduOne) {

View file

@ -24,6 +24,7 @@ import io.github.wulkanowy.sdk.scrapper.notes.Note
import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory
import io.github.wulkanowy.sdk.scrapper.register.AuthorizePermissionPlusRequest
import io.github.wulkanowy.sdk.scrapper.register.RegisterStudent
import io.github.wulkanowy.sdk.scrapper.register.Semester
import io.github.wulkanowy.sdk.scrapper.service.StudentPlusService
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson
import io.github.wulkanowy.sdk.scrapper.timetable.Lesson
@ -356,4 +357,26 @@ internal class StudentPlusRepository(
val key = getEncodedKey(studentId, diaryId, unitId)
return api.getConferences(key)
}
suspend fun getSemesters(studentId: Int, diaryId: Int, unitId: Int): List<Semester> {
val key = getEncodedKey(studentId, diaryId, unitId)
val context = api.getContext()
val student = context.students.find { it.key == key }
val level = student?.className.orEmpty().takeWhile { it.isDigit() }
return api.getSemesters(key, diaryId).map {
Semester(
diaryId = diaryId,
diaryName = student?.className.orEmpty(),
className = student?.className?.replace(level, ""),
schoolYear = it.dataOd.toLocalDate().year,
semesterId = it.id,
semesterNumber = it.numerOkresu,
start = it.dataOd.toLocalDate(),
end = it.dataDo.toLocalDate(),
unitId = unitId,
classId = 0,
kindergartenDiaryId = 0,
)
}
}
}