Fix symbol and school id in register

This commit is contained in:
Mikołaj Pich 2018-12-11 23:10:48 +01:00
parent 1ffe318060
commit a448cfa90c
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
3 changed files with 7 additions and 5 deletions

View file

@ -36,10 +36,10 @@ class RegisterRepository(
if (t is AccountPermissionException) Single.just(HomepageResponse())
else Single.error(t)
}
.flatMapObservable { Observable.fromIterable(if (useNewStudent) it.studentSchools else it.oldStudentSchools) }
.flatMapObservable { if (useNewStudent) Observable.fromIterable(it.studentSchools) else Observable.fromIterable(it.oldStudentSchools) }
.flatMapSingle { schoolUrl ->
getLoginType().flatMap { loginType ->
getStudents(schoolUrl).map {
getStudents(symbol.first, schoolUrl).map {
it.map { pupil ->
Pupil(
email = email,
@ -57,7 +57,9 @@ class RegisterRepository(
}.toList().map { it.flatten() }
}
private fun getStudents(schoolUrl: String): Single<List<StudentAndParentResponse.Pupil>> {
private fun getStudents(symbol: String, schoolUrl: String): Single<List<StudentAndParentResponse.Pupil>> {
url.schoolId = getExtractedSchoolSymbolFromUrl(schoolUrl)
url.symbol = symbol
return if (!useNewStudent) snp.getSchoolInfo(schoolUrl).map { it.students }
else student.getSchoolInfo(url.generate(ServiceManager.UrlGenerator.Site.STUDENT) + "UczenDziennik.mvc/Get").map { diary -> diary.data?.distinctBy { it.studentId } }
.map { diaries ->

View file

@ -134,7 +134,7 @@ class ServiceManager(
}
}
class UrlGenerator(private val schema: String, private val host: String, private val symbol: String, private val schoolId: String) {
class UrlGenerator(private val schema: String, private val host: String, var symbol: String, var schoolId: String) {
enum class Site {
LOGIN, SNP, STUDENT, MESSAGES

View file

@ -96,7 +96,7 @@ class ApiRemoteTest : BaseTest() {
}
values[4].run {
// assertEquals(15, diaryId)
// assertEquals(15, diaryId)
assertEquals("2A 2016", diaryName)
assertEquals(12, semesterId)
// assertEquals(2, semesterNumber)