Merge pull request #194 from Marioneq4958/eduone-homework
Add student+ homework and fix teacherSymbol in exams
This commit is contained in:
commit
f53776c373
8 changed files with 105 additions and 5 deletions
|
@ -873,6 +873,7 @@ public final class io/github/wulkanowy/sdk/scrapper/homework/Homework {
|
|||
public static final field Companion Lio/github/wulkanowy/sdk/scrapper/homework/Homework$Companion;
|
||||
public field teacherSymbol Ljava/lang/String;
|
||||
public fun <init> (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/time/LocalDateTime;Ljava/time/LocalDateTime;IZLjava/util/List;)V
|
||||
public synthetic fun <init> (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/time/LocalDateTime;Ljava/time/LocalDateTime;IZLjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun component1 ()I
|
||||
public final fun component2 ()Ljava/lang/String;
|
||||
public final fun component3 ()Ljava/lang/String;
|
||||
|
|
|
@ -418,7 +418,10 @@ class Scrapper {
|
|||
suspend fun getHomework(startDate: LocalDate, endDate: LocalDate? = null): List<Homework> {
|
||||
if (diaryId == 0) return emptyList()
|
||||
|
||||
return student.getHomework(startDate, endDate)
|
||||
return when (isEduOne) {
|
||||
true -> studentPlus.getHomework(startDate, endDate, studentId, diaryId, unitId)
|
||||
else -> student.getHomework(startDate, endDate)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getNotes(): List<Note> = student.getNotes()
|
||||
|
|
|
@ -36,7 +36,7 @@ data class Homework(
|
|||
val isAnswerRequired: Boolean,
|
||||
|
||||
@SerialName("Attachments")
|
||||
val attachments: List<HomeworkAttachment>,
|
||||
val attachments: List<HomeworkAttachment> = emptyList(),
|
||||
) {
|
||||
|
||||
@Transient
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.homework
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
internal data class HomeworkDetailsPlus(
|
||||
|
||||
@SerialName("nauczycielImieNazwisko")
|
||||
val teacher: String,
|
||||
|
||||
@SerialName("opis")
|
||||
val description: String,
|
||||
|
||||
@SerialName("status")
|
||||
val status: Int,
|
||||
|
||||
@SerialName("odpowiedzWymagana")
|
||||
val isAnswerRequired: Boolean,
|
||||
|
||||
// TODO: Attachments
|
||||
)
|
|
@ -17,6 +17,7 @@ import io.github.wulkanowy.sdk.scrapper.grades.Grades
|
|||
import io.github.wulkanowy.sdk.scrapper.grades.mapGradesList
|
||||
import io.github.wulkanowy.sdk.scrapper.grades.mapGradesSummary
|
||||
import io.github.wulkanowy.sdk.scrapper.handleErrors
|
||||
import io.github.wulkanowy.sdk.scrapper.homework.Homework
|
||||
import io.github.wulkanowy.sdk.scrapper.mobile.TokenResponse
|
||||
import io.github.wulkanowy.sdk.scrapper.register.AuthorizePermissionPlusRequest
|
||||
import io.github.wulkanowy.sdk.scrapper.register.RegisterStudent
|
||||
|
@ -207,7 +208,7 @@ internal class StudentPlusRepository(
|
|||
subject = exam.subject,
|
||||
type = exam.type,
|
||||
description = examDetailsRes.description,
|
||||
teacher = examDetailsRes.teacher.substringBefore(" ["),
|
||||
teacher = examDetailsRes.teacher,
|
||||
).apply {
|
||||
typeName = when (exam.type) {
|
||||
1 -> "Sprawdzian"
|
||||
|
@ -215,7 +216,32 @@ internal class StudentPlusRepository(
|
|||
else -> "Praca klasowa"
|
||||
}
|
||||
date = exam.date
|
||||
teacherSymbol = examDetailsRes.teacher.substringAfter(" [", "").substringBefore("]")
|
||||
teacherSymbol = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getHomework(startDate: LocalDate, endDate: LocalDate?, studentId: Int, diaryId: Int, unitId: Int): List<Homework> {
|
||||
val key = getEncodedKey(studentId, diaryId, unitId)
|
||||
val examsHomeworkRes = api.getExamsAndHomework(
|
||||
key = key,
|
||||
from = startDate.toISOFormat(),
|
||||
to = endDate?.toISOFormat(),
|
||||
)
|
||||
|
||||
return examsHomeworkRes.filter { it.type == 4 }.map { homework ->
|
||||
val homeworkDetailsRes = api.getHomeworkDetails(key, homework.id)
|
||||
Homework(
|
||||
homeworkId = homework.id,
|
||||
subject = homework.subject,
|
||||
teacher = homeworkDetailsRes.teacher,
|
||||
content = homeworkDetailsRes.description,
|
||||
date = homework.date,
|
||||
entryDate = homework.date,
|
||||
status = homeworkDetailsRes.status,
|
||||
isAnswerRequired = homeworkDetailsRes.isAnswerRequired,
|
||||
).apply {
|
||||
teacherSymbol = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.homework.HomeworkDetailsPlus
|
||||
import io.github.wulkanowy.sdk.scrapper.mobile.Device
|
||||
import io.github.wulkanowy.sdk.scrapper.mobile.TokenResponse
|
||||
import io.github.wulkanowy.sdk.scrapper.register.AuthorizePermissionPlusRequest
|
||||
|
@ -91,4 +92,10 @@ internal interface StudentPlusService {
|
|||
@Query("key") key: String,
|
||||
@Query("id") id: Int,
|
||||
): ExamDetailsPlus
|
||||
|
||||
@GET("api/ZadanieDomoweSzczegoly")
|
||||
suspend fun getHomeworkDetails(
|
||||
@Query("key") key: String,
|
||||
@Query("id") id: Int,
|
||||
): HomeworkDetailsPlus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.homework
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.BaseLocalTest
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class HomeworkPlusTest : BaseLocalTest() {
|
||||
|
||||
private val homework by lazy {
|
||||
runBlocking {
|
||||
getStudentPlusRepo {
|
||||
it.enqueue("SprawdzianyZadaniaDomowe.json", HomeworkPlusTest::class.java)
|
||||
it.enqueue("ZadanieDomoweSzczegoly.json", HomeworkPlusTest::class.java)
|
||||
}.getHomework(
|
||||
startDate = getLocalDate(2024, 10, 18),
|
||||
endDate = getLocalDate(2024, 3, 24),
|
||||
studentId = 1,
|
||||
diaryId = 2,
|
||||
unitId = 3,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getAllTest() {
|
||||
Assert.assertEquals(1, homework.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getHomeworkTest() {
|
||||
with(homework[0]) {
|
||||
Assert.assertEquals(getDate(2024, 3, 19), date)
|
||||
Assert.assertEquals(getDate(2024, 3, 19), entryDate)
|
||||
Assert.assertEquals("Zajęcia artystyczne", subject)
|
||||
Assert.assertEquals("opis zadania", content)
|
||||
Assert.assertEquals("Jan Kowalski", teacher)
|
||||
Assert.assertEquals("", teacherSymbol)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ internal fun List<ScrapperExam>.mapExams() = map {
|
|||
date = it.date.toLocalDate(),
|
||||
entryDate = it.entryDate.toLocalDate(),
|
||||
description = it.description,
|
||||
teacherSymbol = it.teacherSymbol,
|
||||
teacherSymbol = it.teacherSymbol.orEmpty(),
|
||||
teacher = it.teacher,
|
||||
subject = it.subject,
|
||||
type = it.typeName,
|
||||
|
|
Loading…
Reference in a new issue