Add info about three switches to Semester

This commit is contained in:
Mikołaj Pich 2020-02-07 00:44:56 +01:00
parent a8c46cca01
commit e5540814bb
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
8 changed files with 98 additions and 52 deletions

View file

@ -13,5 +13,8 @@ data class Semester(
val start: LocalDate = now(), val start: LocalDate = now(),
val end: LocalDate = now(), val end: LocalDate = now(),
val classId: Int = 0, val classId: Int = 0,
val unitId: Int = 0 val unitId: Int = 0,
val feesEnabled: Boolean,
val menuEnabled: Boolean,
val completedLessonsEnabled: Boolean
) )

View file

@ -22,12 +22,17 @@ class StudentAndParentStartRepository(
api.getDiaryInfo(diary.id, "/$symbol/$schoolSymbol/Oceny.mvc/Wszystkie").map { res -> api.getDiaryInfo(diary.id, "/$symbol/$schoolSymbol/Oceny.mvc/Wszystkie").map { res ->
if (!res.title.endsWith("Oceny")) throw VulcanException("Unknow page with title: ${res.title}") if (!res.title.endsWith("Oceny")) throw VulcanException("Unknow page with title: ${res.title}")
res.semesters.map { res.semesters.map {
Semester(diary.id, Semester(
diary.name, diaryId = diary.id,
diary.name.substringAfter(" ").toInt(), diaryName = diary.name,
it.semesterId, schoolYear = diary.name.substringAfter(" ").toInt(),
it.semesterNumber, semesterId = it.semesterId,
"selected" == it.current && "selected" == diary.current) semesterNumber = it.semesterNumber,
current = "selected" == it.current && "selected" == diary.current,
feesEnabled = false,
menuEnabled = false,
completedLessonsEnabled = false
)
} }
} }
}.toList().map { it.flatten() } }.toList().map { it.flatten() }

View file

@ -1,5 +1,6 @@
package io.github.wulkanowy.sdk.scrapper.repository package io.github.wulkanowy.sdk.scrapper.repository
import io.github.wulkanowy.sdk.scrapper.getScriptParam
import io.github.wulkanowy.sdk.scrapper.interceptor.ErrorHandlerTransformer import io.github.wulkanowy.sdk.scrapper.interceptor.ErrorHandlerTransformer
import io.github.wulkanowy.sdk.scrapper.register.Semester import io.github.wulkanowy.sdk.scrapper.register.Semester
import io.github.wulkanowy.sdk.scrapper.service.StudentService import io.github.wulkanowy.sdk.scrapper.service.StudentService
@ -15,11 +16,19 @@ class StudentStartRepository(
) { ) {
companion object { companion object {
@JvmStatic private val logger = LoggerFactory.getLogger(this::class.java) @JvmStatic
private val logger = LoggerFactory.getLogger(this::class.java)
} }
fun getSemesters(): Single<List<Semester>> { fun getSemesters(): Single<List<Semester>> {
return api.getDiaries() return api.getStart("Start").flatMap {
api.getUserCache(
getScriptParam("antiForgeryToken", it),
getScriptParam("appGuid", it),
getScriptParam("version", it)
)
}.compose(ErrorHandlerTransformer()).map { it.data }.flatMap { cache ->
api.getDiaries()
.compose(ErrorHandlerTransformer()) .compose(ErrorHandlerTransformer())
.map { it.data.orEmpty() } .map { it.data.orEmpty() }
.map { diaries -> .map { diaries ->
@ -39,7 +48,10 @@ class StudentStartRepository(
end = it.end.toLocalDate(), end = it.end.toLocalDate(),
current = it.start.toLocalDate() <= now() && it.end.toLocalDate() >= now(), current = it.start.toLocalDate() <= now() && it.end.toLocalDate() >= now(),
classId = it.classId, classId = it.classId,
unitId = it.unitId unitId = it.unitId,
menuEnabled = cache.isMenu,
feesEnabled = cache.isFees,
completedLessonsEnabled = cache.showCompletedLessons
) )
} }
} }
@ -50,6 +62,7 @@ class StudentStartRepository(
logger.debug("Diaries size: $diaries") logger.debug("Diaries size: $diaries")
emptyList() emptyList()
} }
}
}.map { }.map {
if (it.isNotEmpty() && it.singleOrNull { semester -> semester.current } == null) it.apply { first().current = true } if (it.isNotEmpty() && it.singleOrNull { semester -> semester.current } == null) it.apply { first().current = true }
else it else it

View file

@ -8,6 +8,15 @@ class CacheResponse {
@SerializedName("czyOpiekun") @SerializedName("czyOpiekun")
var isParent: Boolean = false var isParent: Boolean = false
@SerializedName("czyJadlospis")
var isMenu: Boolean = false
@SerializedName("czyOplaty")
var isFees: Boolean = false
@SerializedName("pokazLekcjeZrealizowane")
var showCompletedLessons: Boolean = false
@SerializedName("poryLekcji") @SerializedName("poryLekcji")
lateinit var times: List<Time> lateinit var times: List<Time>

View file

@ -5,7 +5,6 @@ import io.github.wulkanowy.sdk.scrapper.BaseLocalTest
import io.github.wulkanowy.sdk.scrapper.register.RegisterTest import io.github.wulkanowy.sdk.scrapper.register.RegisterTest
import io.github.wulkanowy.sdk.scrapper.register.Semester import io.github.wulkanowy.sdk.scrapper.register.Semester
import io.reactivex.observers.TestObserver import io.reactivex.observers.TestObserver
import okhttp3.mockwebserver.MockResponse
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
@ -28,7 +27,9 @@ class StudentStartRepositoryTest : BaseLocalTest() {
@Test @Test
fun getSemesters() { fun getSemesters() {
server.enqueue(MockResponse().setBody(RegisterTest::class.java.getResource("UczenDziennik.json").readText())) server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
server.enqueue("UczenCache.json", RegisterTest::class.java)
server.enqueue("UczenDziennik.json", RegisterTest::class.java)
server.start(3000) // server.start(3000) //
api.studentId = 1 api.studentId = 1
@ -56,7 +57,9 @@ class StudentStartRepositoryTest : BaseLocalTest() {
@Test @Test
fun getSemesters_empty() { fun getSemesters_empty() {
server.enqueue(MockResponse().setBody(RegisterTest::class.java.getResource("UczenDziennik.json").readText())) server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
server.enqueue("UczenCache.json", RegisterTest::class.java)
server.enqueue("UczenDziennik.json", RegisterTest::class.java)
server.start(3000) // server.start(3000) //
api.studentId = 1 api.studentId = 1
@ -74,7 +77,9 @@ class StudentStartRepositoryTest : BaseLocalTest() {
@Test @Test
fun getSemesters_studentWithMultiClasses() { fun getSemesters_studentWithMultiClasses() {
server.enqueue(MockResponse().setBody(RegisterTest::class.java.getResource("UczenDziennik-multi.json").readText())) server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
server.enqueue("UczenCache.json", RegisterTest::class.java)
server.enqueue("UczenDziennik-multi.json", RegisterTest::class.java)
server.start(3000) // server.start(3000) //
api.studentId = 3881 api.studentId = 3881
@ -96,7 +101,9 @@ class StudentStartRepositoryTest : BaseLocalTest() {
@Test @Test
fun getSemesters_graduate() { fun getSemesters_graduate() {
server.enqueue(MockResponse().setBody(RegisterTest::class.java.getResource("UczenDziennik.json").readText())) server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
server.enqueue("UczenCache.json", RegisterTest::class.java)
server.enqueue("UczenDziennik.json", RegisterTest::class.java)
server.start(3000) // server.start(3000) //
api.studentId = 2 api.studentId = 2

View file

@ -23,7 +23,10 @@ fun List<ScrapperSemester>.mapSemesters(): List<Semester> {
start = it.start, start = it.start,
end = it.end, end = it.end,
classId = it.classId, classId = it.classId,
unitId = it.unitId unitId = it.unitId,
feesEnabled = it.feesEnabled,
menuEnabled = it.menuEnabled,
completedLessonsEnabled = it.completedLessonsEnabled
) )
} }
} }
@ -40,7 +43,10 @@ fun List<Student>.mapSemesters(studentId: Int, now: LocalDate = now()): List<Sem
start = it.periodDateFrom.toLocalDate(), start = it.periodDateFrom.toLocalDate(),
end = it.periodDateTo.toLocalDate(), end = it.periodDateTo.toLocalDate(),
classId = it.classId, classId = it.classId,
unitId = it.reportingUnitId unitId = it.reportingUnitId,
feesEnabled = false,
menuEnabled = false,
completedLessonsEnabled = false
) )
}.mockSecondSemester(now) }.mockSecondSemester(now)
} }

View file

@ -13,5 +13,8 @@ data class Semester(
val start: LocalDate, val start: LocalDate,
val end: LocalDate, val end: LocalDate,
val classId: Int, val classId: Int,
val unitId: Int val unitId: Int,
val feesEnabled: Boolean,
val menuEnabled: Boolean,
val completedLessonsEnabled: Boolean
) )

View file

@ -161,7 +161,7 @@ class SdkRemoteTest {
} }
val subjects = sdk.getSubjects().blockingGet() val subjects = sdk.getSubjects().blockingGet()
assertEquals(14, subjects.size) assertEquals(15, subjects.size)
} }
@Test @Test
@ -237,7 +237,7 @@ class SdkRemoteTest {
} }
val timetable = sdk.getTimetable(of(2018, 1, 1), of(2018, 1, 2)).blockingGet() val timetable = sdk.getTimetable(of(2018, 1, 1), of(2018, 1, 2)).blockingGet()
assertEquals(24, timetable.size) assertEquals(28, timetable.size)
} }
@Test @Test