From 4071569fb4da12a3d14d063fd2eb0f6dc865ae96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Tue, 19 Mar 2024 18:01:45 +0100 Subject: [PATCH] Fix syntax and missing imports --- .../github/wulkanowy/sdk/scrapper/Scrapper.kt | 2 +- .../sdk/scrapper/exams/ExamDetailsPlus.kt | 3 +-- .../sdk/scrapper/homework/ExamHomeworkPlus.kt | 18 ++++++++++----- .../repository/StudentPlusRepository.kt | 23 +++++++++++-------- .../scrapper/service/StudentPlusService.kt | 6 +++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt index 2eba781d..fcbfb0ff 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt @@ -371,7 +371,7 @@ class Scrapper { suspend fun getExams(startDate: LocalDate, endDate: LocalDate? = null): List { 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) } } diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/exams/ExamDetailsPlus.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/exams/ExamDetailsPlus.kt index d2241834..fbf18a4a 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/exams/ExamDetailsPlus.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/exams/ExamDetailsPlus.kt @@ -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, diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/homework/ExamHomeworkPlus.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/homework/ExamHomeworkPlus.kt index b823902d..bd4337e4 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/homework/ExamHomeworkPlus.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/homework/ExamHomeworkPlus.kt @@ -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, ) diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentPlusRepository.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentPlusRepository.kt index 4749d061..bc22f3c3 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentPlusRepository.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentPlusRepository.kt @@ -160,27 +160,32 @@ internal class StudentPlusRepository( ) } - suspend fun getExams(startDate: LocalDate, endDate: LocalDate): List { + suspend fun getExams(startDate: LocalDate, endDate: LocalDate?, studentId: Int, diaryId: Int, unitId: Int): List { 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("]") + } } } } diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/StudentPlusService.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/StudentPlusService.kt index 4d32b61f..d2a226d2 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/StudentPlusService.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/StudentPlusService.kt @@ -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 @GET("api/SprawdzianSzczegoly") suspend fun getExamDetails( @Query("key") key: String, - @Query("id") id: Int + @Query("id") id: Int, ): ExamDetailsPlus }