Add synthetic second semester in mobile api mode

This commit is contained in:
Mikołaj Pich 2019-11-16 21:09:48 +01:00
parent e069951da7
commit 93aece8ad7
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
2 changed files with 13 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import io.github.wulkanowy.sdk.pojo.Semester
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.toLocalDate
import org.threeten.bp.LocalDate.now
import org.threeten.bp.LocalDate.of
import org.threeten.bp.Month
import io.github.wulkanowy.sdk.scrapper.register.Semester as ScrapperSemester
@ -39,5 +40,16 @@ fun List<Student>.mapSemesters(studentId: Int): List<Semester> {
classId = it.classId,
unitId = it.reportingUnitId
)
}.let {
if (it.size == 1) {
val semesterNumber = it.single().semesterNumber
listOf(it.single(), it.single().copy(
current = false,
semesterNumber = if (semesterNumber == 1) 2 else 1,
semesterId = if (semesterNumber == 1) it.single().semesterId + 1 else it.single().semesterId - 1,
start = if (semesterNumber == 1) it.single().end.plusDays(1) else of(it.single().schoolYear, 9, 1),
end = if (semesterNumber == 1) of(it.single().schoolYear + 1, 6, 30) else it.single().start.plusDays(1)
))
} else it
}
}

View file

@ -58,7 +58,7 @@ class SdkRemoteTest {
}
val semesters = sdk.getSemesters().blockingGet()
assertEquals(1, semesters.size)
assertEquals(2, semesters.size)
}
@Test