Fix syntax and missing imports

This commit is contained in:
Mikołaj Pich 2024-03-19 18:01:45 +01:00
parent 1c67564742
commit 4071569fb4
No known key found for this signature in database
5 changed files with 32 additions and 20 deletions

View file

@ -371,7 +371,7 @@ class Scrapper {
suspend fun getExams(startDate: LocalDate, endDate: LocalDate? = null): List<Exam> {
if (diaryId == 0) return emptyList()
return when (isEduOne) {
true -> studentPlus.getExams(startDate, endDate)
true -> studentPlus.getExams(startDate, endDate, studentId, diaryId, unitId)
else -> student.getExams(startDate, endDate)
}
}

View file

@ -2,10 +2,9 @@ package io.github.wulkanowy.sdk.scrapper.exams
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.time.LocalDateTime
@Serializable
data class ExamDetailsPlus(
internal data class ExamDetailsPlus(
@SerialName("nauczycielImieNazwisko")
val teacher: String,

View file

@ -1,17 +1,23 @@
package io.github.wulkanowy.sdk.scrapper.homework
import io.github.wulkanowy.sdk.scrapper.adapter.CustomDateAdapter
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.time.LocalDateTime
@Serializable
data class ExamHomeworkPlus(
internal data class ExamHomeworkPlus(
@SerialName("typ")
val type: Int,
@SerialName("przedmiotNazwa")
val subject: String,
@SerialName("data")
@Serializable(with = CustomDateAdapter::class)
val date: LocalDateTime,
@SerialName("id")
val id: Int
val id: Int,
)

View file

@ -160,27 +160,32 @@ internal class StudentPlusRepository(
)
}
suspend fun getExams(startDate: LocalDate, endDate: LocalDate): List<Exam> {
suspend fun getExams(startDate: LocalDate, endDate: LocalDate?, studentId: Int, diaryId: Int, unitId: Int): List<Exam> {
val key = getEncodedKey(studentId, diaryId, unitId)
val examsHomeworkRes = api.getExamsAndHomework(key, startDate, endDate)
val examsHomeworkRes = api.getExamsAndHomework(
key = key,
from = startDate.toISOFormat(),
to = endDate?.toISOFormat(),
)
examsHomeworkRes.filter { it.type != 4 }.map { exam ->
return examsHomeworkRes.filter { it.type != 4 }.map { exam ->
val examDetailsRes = api.getExamDetails(key, exam.id)
val teacherAndSymbol = examDetailsRes.teacher.split(" [")
return Exam(
entryDate = null,
Exam(
entryDate = exam.date,
subject = exam.subject,
type = exam.type,
description = examDetailsRes.description,
teacher = teacherAndSymbol.first(),
).apply {
typeName = when (exam.type) {
1 -> "Sprawdzian"
2 -> "Kartkówka"
else -> "Praca klasowa"
},
date = exam.date,
teacherSymbol = teacherAndSymbol.last().removeSuffix("]"),
)
}
date = exam.date
teacherSymbol = teacherAndSymbol.last().removeSuffix("]")
}
}
}
}

View file

@ -4,8 +4,10 @@ import io.github.wulkanowy.sdk.scrapper.attendance.Attendance
import io.github.wulkanowy.sdk.scrapper.attendance.AttendanceExcusePlusRequest
import io.github.wulkanowy.sdk.scrapper.attendance.AttendanceExcusesPlusResponse
import io.github.wulkanowy.sdk.scrapper.conferences.Conference
import io.github.wulkanowy.sdk.scrapper.exams.ExamDetailsPlus
import io.github.wulkanowy.sdk.scrapper.grades.GradeSemester
import io.github.wulkanowy.sdk.scrapper.grades.GradesResponse
import io.github.wulkanowy.sdk.scrapper.homework.ExamHomeworkPlus
import io.github.wulkanowy.sdk.scrapper.mobile.Device
import io.github.wulkanowy.sdk.scrapper.mobile.TokenResponse
import io.github.wulkanowy.sdk.scrapper.register.AuthorizePermissionPlusRequest
@ -75,12 +77,12 @@ internal interface StudentPlusService {
suspend fun getExamsAndHomework(
@Query("key") key: String,
@Query("dataOd") from: String,
@Query("dataDo") to: String,
@Query("dataDo") to: String?,
): List<ExamHomeworkPlus>
@GET("api/SprawdzianSzczegoly")
suspend fun getExamDetails(
@Query("key") key: String,
@Query("id") id: Int
@Query("id") id: Int,
): ExamDetailsPlus
}