Normalize student and school ids type
This commit is contained in:
parent
7c89e24748
commit
1400211f0d
8 changed files with 22 additions and 22 deletions
|
@ -24,9 +24,9 @@ class Api {
|
|||
|
||||
var schoolSymbol: String = ""
|
||||
|
||||
var studentId: String = ""
|
||||
var studentId: Int = 0
|
||||
|
||||
var diaryId: String = ""
|
||||
var diaryId: Int = 0
|
||||
|
||||
enum class LoginType {
|
||||
AUTO,
|
||||
|
@ -57,7 +57,7 @@ class Api {
|
|||
}
|
||||
|
||||
private val snpStart by resettableLazy(changeManager) {
|
||||
if (studentId.isBlank()) throw ApiException("Student id is not set")
|
||||
if (0 == studentId) throw ApiException("Student id is not set")
|
||||
StudentAndParentStartRepository(normalizedSymbol, schoolSymbol, studentId, serviceManager.getSnpService(true, false))
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ class Api {
|
|||
}
|
||||
|
||||
private val messages by resettableLazy(changeManager) {
|
||||
MessagesRepository(studentId.toInt(), serviceManager.getMessagesService())
|
||||
MessagesRepository(studentId, serviceManager.getMessagesService())
|
||||
}
|
||||
|
||||
fun setInterceptor(interceptor: Interceptor, index: Int = -1) {
|
||||
|
|
|
@ -10,8 +10,8 @@ class StudentAndParentInterceptor(
|
|||
private val cookies: CookieManager,
|
||||
private val schema: String,
|
||||
private val host: String,
|
||||
private val diaryId: String,
|
||||
private val studentId: String
|
||||
private val diaryId: Int,
|
||||
private val studentId: Int
|
||||
) : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
|
@ -19,7 +19,7 @@ class StudentAndParentInterceptor(
|
|||
arrayOf("idBiezacyDziennik", diaryId),
|
||||
arrayOf("idBiezacyUczen", studentId)
|
||||
).forEach { cookie ->
|
||||
HttpCookie(cookie[0], cookie[1]).let {
|
||||
HttpCookie(cookie[0].toString(), cookie[1].toString()).let {
|
||||
it.path = "/"
|
||||
it.domain = "uonetplus-opiekun.$host"
|
||||
cookies.cookieStore.add(URI("$schema://${it.domain}"), it)
|
||||
|
|
|
@ -7,14 +7,14 @@ import io.reactivex.Single
|
|||
|
||||
class StudentAndParentStartRepository(
|
||||
private val symbol: String,
|
||||
private val schoolId: String,
|
||||
private val studentId: String,
|
||||
private val schoolSymbol: String,
|
||||
private val studentId: Int,
|
||||
private val api: StudentAndParentService
|
||||
) {
|
||||
|
||||
fun getSemesters(): Single<List<Semester>> {
|
||||
return api.getUserInfo(studentId).flatMapObservable { Observable.fromIterable(it.diaries.reversed()) }.flatMapSingle { diary ->
|
||||
api.getDiaryInfo(diary.id, "/$symbol/$schoolId/Oceny.mvc/Wszystkie").map { res ->
|
||||
api.getDiaryInfo(diary.id, "/$symbol/$schoolSymbol/Oceny.mvc/Wszystkie").map { res ->
|
||||
res.semesters.map {
|
||||
Semester(diary.id, diary.name, it.semesterId, it.semesterNumber, "selected" == it.current && "selected" == diary.current)
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ class ServiceManager(
|
|||
private val symbol: String,
|
||||
private val email: String,
|
||||
private val password: String,
|
||||
private val schoolId: String,
|
||||
private val studentId: String,
|
||||
private val diaryId: String
|
||||
private val schoolSymbol: String,
|
||||
private val studentId: Int,
|
||||
private val diaryId: Int
|
||||
) {
|
||||
|
||||
private val cookies by lazy {
|
||||
|
@ -39,7 +39,7 @@ class ServiceManager(
|
|||
}
|
||||
|
||||
private val url by lazy {
|
||||
UrlGenerator(schema, host, symbol, schoolId)
|
||||
UrlGenerator(schema, host, symbol, schoolSymbol)
|
||||
}
|
||||
|
||||
private val interceptors: MutableList<Interceptor> = mutableListOf(
|
||||
|
@ -62,11 +62,11 @@ class ServiceManager(
|
|||
}
|
||||
|
||||
fun getSnpService(withLogin: Boolean = true, interceptor: Boolean = true): StudentAndParentService {
|
||||
if (withLogin && schoolId.isBlank()) throw ApiException("School id is not set")
|
||||
if (withLogin && schoolSymbol.isBlank()) throw ApiException("School id is not set")
|
||||
|
||||
val client = getClientBuilder()
|
||||
if (interceptor) {
|
||||
if (diaryId.isBlank() || studentId.isBlank()) throw ApiException("Student or/and diaryId id are not set")
|
||||
if (0 == diaryId || 0 == studentId) throw ApiException("Student or/and diaryId id are not set")
|
||||
client.addInterceptor(StudentAndParentInterceptor(cookies, schema, host, diaryId, studentId))
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ interface StudentAndParentService {
|
|||
fun getSchoolInfo(@Url url: String): Single<StudentAndParentResponse>
|
||||
|
||||
@GET("Uczen/UczenOnChange")
|
||||
fun getUserInfo(@Query("id") userId: String): Single<StudentAndParentResponse>
|
||||
fun getUserInfo(@Query("id") userId: Int): Single<StudentAndParentResponse>
|
||||
|
||||
@GET("Dziennik/DziennikOnChange")
|
||||
fun getDiaryInfo(@Query("id") diaryId: Int, @Header("Referer") referer: String): Single<StudentAndParentResponse>
|
||||
|
|
|
@ -43,8 +43,8 @@ class ApiTest : BaseTest() {
|
|||
email = "jan@fakelog.cf"
|
||||
password = "jan123"
|
||||
schoolSymbol = "123456"
|
||||
studentId = "1"
|
||||
diaryId = "101"
|
||||
studentId = 1
|
||||
diaryId = 101
|
||||
notifyDataChanged() // unnecessary in this case
|
||||
setInterceptor(Interceptor { // important! put bellow notifyDataChanged
|
||||
println("Request event ${it.request().url().host()}")
|
||||
|
|
|
@ -43,7 +43,7 @@ class RegisterTest : BaseTest() {
|
|||
}
|
||||
|
||||
private val snp by lazy {
|
||||
StudentAndParentStartRepository("default", "0012345", "123",
|
||||
StudentAndParentStartRepository("default", "0012345", 123,
|
||||
getService(StudentAndParentService::class.java, "http://fakelog.localhost:3000/"))
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class ServiceManagerTest : BaseTest() {
|
|||
fun interceptorTest() {
|
||||
val manager = ServiceManager(HttpLoggingInterceptor.Level.NONE,
|
||||
Api.LoginType.STANDARD, "http", "fakelog.localhost:3000", "default", "email", "password",
|
||||
"schoolSymbol", "studentId", "diaryId"
|
||||
"schoolSymbol", 123, 101
|
||||
)
|
||||
manager.setInterceptor(Interceptor {
|
||||
throw ApiException("Test")
|
||||
|
@ -57,7 +57,7 @@ class ServiceManagerTest : BaseTest() {
|
|||
server.start(3000)
|
||||
val manager = ServiceManager(HttpLoggingInterceptor.Level.NONE,
|
||||
Api.LoginType.STANDARD, "http", "fakelog.localhost:3000", "default", "email", "password",
|
||||
"schoolSymbol", "studentId", "diaryId"
|
||||
"schoolSymbol", 123, 101
|
||||
)
|
||||
manager.setInterceptor(Interceptor {
|
||||
throw IOException("Test")
|
||||
|
|
Loading…
Reference in a new issue