Add missing key query param to mobile devices, school and teachers endpoints

This commit is contained in:
Mikołaj Pich 2024-03-23 14:51:50 +01:00
parent 28fc7a7d40
commit cd31377aed
No known key found for this signature in database
6 changed files with 53 additions and 34 deletions

View file

@ -474,7 +474,7 @@ class Scrapper {
} }
suspend fun getRegisteredDevices(): List<Device> = when (isEduOne) { suspend fun getRegisteredDevices(): List<Device> = when (isEduOne) {
true -> studentPlus.getRegisteredDevices() true -> studentPlus.getRegisteredDevices(studentId, diaryId, unitId)
else -> student.getRegisteredDevices() else -> student.getRegisteredDevices()
} }
@ -488,12 +488,12 @@ class Scrapper {
suspend fun unregisterDevice(id: Int): Boolean = student.unregisterDevice(id) suspend fun unregisterDevice(id: Int): Boolean = student.unregisterDevice(id)
suspend fun getTeachers(): List<Teacher> = when (isEduOne) { suspend fun getTeachers(): List<Teacher> = when (isEduOne) {
true -> studentPlus.getTeachers() true -> studentPlus.getTeachers(studentId, diaryId, unitId)
else -> student.getTeachers() else -> student.getTeachers()
} }
suspend fun getSchool(): School = when (isEduOne) { suspend fun getSchool(): School = when (isEduOne) {
true -> studentPlus.getSchool() true -> studentPlus.getSchool(studentId, diaryId, unitId)
else -> student.getSchool() else -> student.getSchool()
} }

View file

@ -179,7 +179,10 @@ internal class StudentPlusRepository(
).mapCompletedLessons(startDate, endDate) ).mapCompletedLessons(startDate, endDate)
} }
suspend fun getRegisteredDevices(): List<Device> = api.getRegisteredDevices() suspend fun getRegisteredDevices(studentId: Int, diaryId: Int, unitId: Int): List<Device> {
val key = getEncodedKey(studentId, diaryId, unitId)
return api.getRegisteredDevices(key)
}
suspend fun getToken(): TokenResponse { suspend fun getToken(): TokenResponse {
val res = api.getDeviceRegistrationToken() val res = api.getDeviceRegistrationToken()
@ -406,33 +409,39 @@ internal class StudentPlusRepository(
} }
} }
suspend fun getTeachers(): List<Teacher> = api.getTeachers().teachers.map { suspend fun getTeachers(studentId: Int, diaryId: Int, unitId: Int): List<Teacher> {
Teacher( val key = getEncodedKey(studentId, diaryId, unitId)
name = "${it.firstName} ${it.lastName}".trim(), return api.getTeachers(key).teachers.map {
subject = it.subject, Teacher(
) name = "${it.firstName} ${it.lastName}".trim(),
subject = it.subject,
)
}
} }
suspend fun getSchool(): School = api.getSchool().let { suspend fun getSchool(studentId: Int, diaryId: Int, unitId: Int): School {
val streetNumber = it.buildingNumber + it.apartmentNumber.takeIf(String::isNotEmpty)?.let { "/$it" }.orEmpty() val key = getEncodedKey(studentId, diaryId, unitId)
val name = buildString { return api.getSchool(key).let {
append(it.name) val streetNumber = it.buildingNumber + it.apartmentNumber.takeIf(String::isNotEmpty)?.let { "/$it" }.orEmpty()
if (it.number.isNotEmpty()) { val name = buildString {
append(" nr ${it.number}") append(it.name)
} if (it.number.isNotEmpty()) {
if (it.patron.isNotEmpty()) { append(" nr ${it.number}")
append(" im. ${it.patron}") }
} if (it.patron.isNotEmpty()) {
if (it.town.isNotEmpty()) { append(" im. ${it.patron}")
append(" w ${it.town}") }
if (it.town.isNotEmpty()) {
append(" w ${it.town}")
}
} }
School(
name = name,
address = "${it.street} $streetNumber, ${it.postcode} ${it.town}",
contact = it.workPhone,
headmaster = it.headmasters.firstOrNull().orEmpty(),
pedagogue = "",
)
} }
School(
name = name,
address = "${it.street} $streetNumber, ${it.postcode} ${it.town}",
contact = it.workPhone,
headmaster = it.headmasters.firstOrNull().orEmpty(),
pedagogue = "",
)
} }
} }

View file

@ -78,7 +78,9 @@ internal interface StudentPlusService {
): AttendanceSummaryResponse ): AttendanceSummaryResponse
@GET("api/ZarejestrowaneUrzadzenia") @GET("api/ZarejestrowaneUrzadzenia")
suspend fun getRegisteredDevices(): List<Device> suspend fun getRegisteredDevices(
@Query("key") key: String,
): List<Device>
@GET("api/RejestracjaUrzadzeniaToken") @GET("api/RejestracjaUrzadzeniaToken")
suspend fun getDeviceRegistrationToken(): TokenResponse suspend fun getDeviceRegistrationToken(): TokenResponse
@ -140,8 +142,12 @@ internal interface StudentPlusService {
suspend fun getNotes(@Query("key") key: String): List<Note> suspend fun getNotes(@Query("key") key: String): List<Note>
@GET("api/Nauczyciele") @GET("api/Nauczyciele")
suspend fun getTeachers(): TeacherPlusResponse suspend fun getTeachers(
@Query("key") key: String,
): TeacherPlusResponse
@GET("api/Informacje") @GET("api/Informacje")
suspend fun getSchool(): SchoolPlus suspend fun getSchool(
@Query("key") key: String,
): SchoolPlus
} }

View file

@ -11,7 +11,7 @@ class DevicesPlusTest : BaseLocalTest() {
private val devices by lazy { private val devices by lazy {
runBlocking { runBlocking {
getStudentPlusRepo(DevicesPlusTest::class.java, "UrzadzeniaPlus.json") getStudentPlusRepo(DevicesPlusTest::class.java, "UrzadzeniaPlus.json")
.getRegisteredDevices() .getRegisteredDevices(1, 2, 3)
} }
} }

View file

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

View file

@ -7,7 +7,10 @@ import org.junit.Test
class TeachersPlusTest : BaseLocalTest() { class TeachersPlusTest : BaseLocalTest() {
private val teachers by lazy { private val teachers by lazy {
runBlocking { getStudentPlusRepo(TeachersPlusTest::class.java, "NauczycielePlus.json").getTeachers() } runBlocking {
getStudentPlusRepo(TeachersPlusTest::class.java, "NauczycielePlus.json")
.getTeachers(1, 2, 3)
}
} }
@Test @Test