Add attendance api

This commit is contained in:
Mikołaj Pich 2018-07-11 14:39:53 +02:00
parent 8b70f4a577
commit 823da05a94
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
6 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,27 @@
package io.github.wulkanowy.sdk.attendance
import com.google.gson.annotations.SerializedName
data class Attendance(
@SerializedName("IdKategoria")
val id: Int,
@SerializedName("Numer")
val number: Int,
@SerializedName("IdPoraLekcji")
val lessonTimeId: Int,
@SerializedName("Dzien")
val date: Long,
@SerializedName("DzienTekst")
val dateText: String,
@SerializedName("IdPrzedmiot")
val subjectId: Int,
@SerializedName("PrzedmiotNazwa")
val subjectName: String
)

View file

@ -0,0 +1,22 @@
package io.github.wulkanowy.sdk.attendance
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.base.ApiRequest
data class AttendanceRequest(
@SerializedName("DataPoczatkowa")
val startDate: String,
@SerializedName("DataKoncowa")
val endDate: String,
@SerializedName("IdOddzial")
val classId: Int,
@SerializedName("IdOkresKlasyfikacyjny")
val classificationPeriodId: Int,
@SerializedName("IdUczen")
val studentId: Int
) : ApiRequest()

View file

@ -0,0 +1,21 @@
package io.github.wulkanowy.sdk.attendance
import com.google.gson.annotations.SerializedName
data class AttendanceResponse(
@SerializedName("DataPoczatkowa")
val dateStart: Long,
@SerializedName("DataPoczatkowaTekst")
val dateStartText: String,
@SerializedName("DataKoncowa")
val dateEnd: Long,
@SerializedName("DataKoncowaTekst")
val dateEndText: String,
@SerializedName("Frekwencje")
val data: List<Attendance>
)

View file

@ -1,5 +1,7 @@
package io.github.wulkanowy.sdk.interfaces
import io.github.wulkanowy.sdk.attendance.AttendanceResponse
import io.github.wulkanowy.sdk.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.base.ApiRequest
import io.github.wulkanowy.sdk.base.ApiResponse
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
@ -35,4 +37,7 @@ interface MobileApi {
@POST("UwagiUcznia")
fun getNotes(@Body notesRequest: NotesRequest): Observable<ApiResponse<List<Note>>>
@POST("Frekwencje")
fun getAttendance(@Body attendanceRequest: AttendanceRequest): Observable<ApiResponse<AttendanceResponse>>
}

View file

@ -1,5 +1,7 @@
package io.github.wulkanowy.sdk.repository
import io.github.wulkanowy.sdk.attendance.AttendanceResponse
import io.github.wulkanowy.sdk.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.base.ApiRequest
import io.github.wulkanowy.sdk.base.ApiResponse
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
@ -47,6 +49,10 @@ class MobileRepository(private val host: String, private val symbol: String, pri
return getMobileApi().getNotes(NotesRequest(classificationPeriodId, studentId))
}
fun getAttendance(startDate: String, endDate: String, classId: Int, classificationPeriodId: Int, studentId: Int): Observable<ApiResponse<AttendanceResponse>> {
return getMobileApi().getAttendance(AttendanceRequest(startDate, endDate, classId, classificationPeriodId, studentId))
}
private fun getMobileApi(): MobileApi {
return Retrofit.Builder()
.baseUrl("$host/$symbol/$reportingUnitSymbol/mobile-api/Uczen.v3.Uczen/")

View file

@ -1,5 +1,6 @@
package io.github.wulkanowy.sdk
import io.github.wulkanowy.sdk.attendance.AttendanceResponse
import io.github.wulkanowy.sdk.base.ApiResponse
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.exams.Exam
@ -92,5 +93,13 @@ class UonetTest {
notesSubscriber.assertCompleted()
notesSubscriber.assertNoErrors()
assertEquals("Ok", notesSubscriber.onNextEvents[0].status)
val attendance = mobile.getAttendance("2018-04-23", "2018-04-24", student.classId, student.classificationPeriodId, student.id)
val attendanceSubscriber = TestSubscriber<ApiResponse<AttendanceResponse>>()
attendance.subscribe(attendanceSubscriber)
attendanceSubscriber.assertCompleted()
attendanceSubscriber.assertNoErrors()
assertEquals("Ok", attendanceSubscriber.onNextEvents[0].status)
assertEquals("2018-04-23", attendanceSubscriber.onNextEvents[0].data!!.dateStartText)
}
}