Add api's notes
This commit is contained in:
parent
97cecaa003
commit
1f3dc8012d
5 changed files with 76 additions and 7 deletions
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.sdk
|
|||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.attendance.Absent
|
||||
import io.github.wulkanowy.sdk.pojo.Attendance
|
||||
import io.github.wulkanowy.api.messages.Folder
|
||||
import io.github.wulkanowy.api.messages.Recipient
|
||||
import io.github.wulkanowy.api.resettableLazy
|
||||
|
@ -13,9 +12,8 @@ import io.github.wulkanowy.sdk.exams.mapExams
|
|||
import io.github.wulkanowy.sdk.grades.mapGrades
|
||||
import io.github.wulkanowy.sdk.grades.mapGradesSummary
|
||||
import io.github.wulkanowy.sdk.interceptor.SignInterceptor
|
||||
import io.github.wulkanowy.sdk.pojo.Exam
|
||||
import io.github.wulkanowy.sdk.pojo.Grade
|
||||
import io.github.wulkanowy.sdk.pojo.Student
|
||||
import io.github.wulkanowy.sdk.notes.mapNotes
|
||||
import io.github.wulkanowy.sdk.pojo.*
|
||||
import io.github.wulkanowy.sdk.register.mapStudents
|
||||
import io.github.wulkanowy.sdk.repository.MobileRepository
|
||||
import io.github.wulkanowy.sdk.repository.RegisterRepository
|
||||
|
@ -294,7 +292,7 @@ class Sdk {
|
|||
}
|
||||
}
|
||||
|
||||
fun getGradesSummary(semesterId: Int): Single<List<io.github.wulkanowy.sdk.pojo.GradeSummary>> {
|
||||
fun getGradesSummary(semesterId: Int): Single<List<GradeSummary>> {
|
||||
return when (mode) {
|
||||
Mode.SCRAPPER -> scrapper.getGradesSummary(semesterId).map { it.mapGradesSummary() }
|
||||
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
|
||||
|
@ -307,7 +305,14 @@ class Sdk {
|
|||
|
||||
fun getHomework(start: LocalDate, end: LocalDate? = null) = scrapper.getHomework(start, end)
|
||||
|
||||
fun getNotes() = scrapper.getNotes()
|
||||
fun getNotes(semesterId: Int): Single<List<Note>> {
|
||||
return when (mode) {
|
||||
Mode.SCRAPPER -> scrapper.getNotes().map { it.mapNotes() }
|
||||
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
|
||||
mobile.getNotes(semesterId, studentId).map { it.mapNotes(dict) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getRegisteredDevices() = scrapper.getRegisteredDevices()
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ data class Note(
|
|||
val employeeSurname: String,
|
||||
|
||||
@SerializedName("DataWpisu")
|
||||
val entryDate: String,
|
||||
val entryDate: Long,
|
||||
|
||||
@SerializedName("DataWpisuTekst")
|
||||
val entryDateText: String,
|
||||
|
|
32
src/main/kotlin/io/github/wulkanowy/sdk/notes/NotesMapper.kt
Normal file
32
src/main/kotlin/io/github/wulkanowy/sdk/notes/NotesMapper.kt
Normal file
|
@ -0,0 +1,32 @@
|
|||
package io.github.wulkanowy.sdk.notes
|
||||
|
||||
import io.github.wulkanowy.api.toLocalDate
|
||||
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
|
||||
import io.github.wulkanowy.sdk.pojo.Note
|
||||
import io.github.wulkanowy.sdk.toLocalDate
|
||||
import io.github.wulkanowy.sdk.notes.Note as ApiNote
|
||||
import io.github.wulkanowy.api.notes.Note as ScrapperNote
|
||||
|
||||
fun List<ApiNote>.mapNotes(dictionaries: Dictionaries): List<Note> {
|
||||
return map {
|
||||
Note(
|
||||
date = it.entryDate.toLocalDate(),
|
||||
content = it.content,
|
||||
category = dictionaries.noteCategories.singleOrNull { cat -> cat.id == it.noteCategoryId }?.name.orEmpty(),
|
||||
teacherSymbol = dictionaries.teachers.singleOrNull { teacher -> teacher.id == it.employeeId }?.code.orEmpty(),
|
||||
teacher = "${it.employeeName} ${it.employeeSurname}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<ScrapperNote>.mapNotes(): List<Note> {
|
||||
return map {
|
||||
Note(
|
||||
date = it.date.toLocalDate(),
|
||||
teacher = it.teacher,
|
||||
teacherSymbol = it.teacherSymbol,
|
||||
category = it.category,
|
||||
content = it.content
|
||||
)
|
||||
}
|
||||
}
|
11
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Note.kt
Normal file
11
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Note.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package io.github.wulkanowy.sdk.pojo
|
||||
|
||||
import org.threeten.bp.LocalDate
|
||||
|
||||
data class Note(
|
||||
var date: LocalDate,
|
||||
var teacher: String,
|
||||
var teacherSymbol: String,
|
||||
var category: String,
|
||||
var content: String
|
||||
)
|
|
@ -148,4 +148,25 @@ class SdkRemoteTest {
|
|||
val attendance = sdk.getAttendance(of(2018, 1, 1), of(2018, 1, 2), 1).blockingGet()
|
||||
assertEquals(24, attendance.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getNotes_api() {
|
||||
val sdk = Sdk().apply {
|
||||
apiKey = API_KEY
|
||||
|
||||
certKey = CERT_KEY
|
||||
certificate = CERTIFICATE
|
||||
|
||||
apiBaseUrl = "https://api.fakelog.cf/Default"
|
||||
mode = Sdk.Mode.API
|
||||
symbol = "Default"
|
||||
|
||||
schoolSymbol = "123456"
|
||||
studentId = 15
|
||||
classId = 14
|
||||
}
|
||||
|
||||
val notes = sdk.getNotes(1).blockingGet()
|
||||
assertEquals(5, notes.size)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue