Fix getToken implementation

This commit is contained in:
Mikołaj Pich 2024-03-23 15:06:28 +01:00
parent dab976890f
commit 545a90e2a0
No known key found for this signature in database
4 changed files with 17 additions and 6 deletions

View file

@ -480,7 +480,7 @@ class Scrapper {
suspend fun getToken(): TokenResponse {
return when (isEduOne) {
true -> studentPlus.getToken()
true -> studentPlus.getToken(studentId, diaryId, unitId)
else -> student.getToken()
}
}

View file

@ -184,8 +184,10 @@ internal class StudentPlusRepository(
return api.getRegisteredDevices(key)
}
suspend fun getToken(): TokenResponse {
val res = api.getDeviceRegistrationToken()
suspend fun getToken(studentId: Int, diaryId: Int, unitId: Int): TokenResponse {
val key = getEncodedKey(studentId, diaryId, unitId)
api.createDeviceRegistrationToken(mapOf("key" to key))
val res = api.getDeviceRegistrationToken(key)
return res.copy(
qrCodeImage = Jsoup.parse(res.qrCodeImage)
.select("img")

View file

@ -82,8 +82,15 @@ internal interface StudentPlusService {
@Query("key") key: String,
): List<Device>
@POST("api/RejestracjaUrzadzeniaToken")
suspend fun createDeviceRegistrationToken(
@Body body: Map<String, String>,
)
@GET("api/RejestracjaUrzadzeniaToken")
suspend fun getDeviceRegistrationToken(): TokenResponse
suspend fun getDeviceRegistrationToken(
@Query("key") key: String,
): TokenResponse
@GET("api/Zebrania")
suspend fun getConferences(

View file

@ -8,8 +8,10 @@ import org.junit.Test
class SchoolPlusTest : BaseLocalTest() {
private val school by lazy {
runBlocking { getStudentPlusRepo(SchoolPlusTest::class.java, "SzkolaPlus.json")
.getSchool(1, 2, 3) }
runBlocking {
getStudentPlusRepo(SchoolPlusTest::class.java, "SzkolaPlus.json")
.getSchool(1, 2, 3)
}
}
@Test