Add student info

This commit is contained in:
Mikołaj Pich 2020-11-29 22:27:10 +01:00
parent ebaf78312d
commit d74d684b72
10 changed files with 269 additions and 159 deletions

View file

@ -224,12 +224,11 @@ class StudentRepository(private val api: StudentService) {
}
suspend fun getSchool(): School {
return api.getSchoolAndTeachers().handleErrors().data?.school!!
return api.getSchoolAndTeachers().handleErrors().data.let { requireNotNull(it?.school) }
}
suspend fun getStudentInfo(): StudentInfo {
// return api.getStudentInfo()
return StudentInfo()
return api.getStudentInfo().handleErrors().let { requireNotNull(it.data) }
}
suspend fun getRegisteredDevices(): List<Device> {

View file

@ -24,6 +24,7 @@ import io.github.wulkanowy.sdk.scrapper.mobile.UnregisterDeviceRequest
import io.github.wulkanowy.sdk.scrapper.notes.NotesResponse
import io.github.wulkanowy.sdk.scrapper.register.Diary
import io.github.wulkanowy.sdk.scrapper.school.SchoolAndTeachersResponse
import io.github.wulkanowy.sdk.scrapper.student.StudentInfo
import io.github.wulkanowy.sdk.scrapper.timetable.CacheResponse
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLessonsRequest
import io.github.wulkanowy.sdk.scrapper.timetable.TimetableRequest
@ -133,5 +134,5 @@ interface StudentService {
suspend fun getSchoolAndTeachers(@Body body: Any = Object()): ApiResponse<SchoolAndTeachersResponse>
@POST("Uczen.mvc/Get")
suspend fun getStudentInfo()
suspend fun getStudentInfo(): ApiResponse<StudentInfo>
}

View file

@ -1,14 +0,0 @@
package io.github.wulkanowy.sdk.scrapper.student
class FamilyMember {
lateinit var fullName: String
lateinit var kinship: String
lateinit var address: String
lateinit var phones: String
lateinit var email: String
}

View file

@ -1,40 +0,0 @@
package io.github.wulkanowy.sdk.scrapper.student
import java.util.Date
class Student {
lateinit var fullName: String
lateinit var firstName: String
lateinit var secondName: String
lateinit var surname: String
lateinit var birthDate: Date
lateinit var birthPlace: String
lateinit var pesel: String
lateinit var gender: String
lateinit var polishCitizenship: String
lateinit var familyName: String
lateinit var parentsNames: String
lateinit var address: String
lateinit var registeredAddress: String
lateinit var correspondenceAddress: String
lateinit var phoneNumber: String
lateinit var cellPhoneNumber: String
lateinit var email: String
}

View file

@ -0,0 +1,41 @@
package io.github.wulkanowy.sdk.scrapper.student
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class StudentGuardian(
@Json(name = "Id")
val id: Int,
@Json(name = "Imie")
val name: String,
@Json(name = "Nazwisko")
val lastName: String,
@Json(name = "StPokrewienstwa")
val kinship: String,
@Json(name = "Adres")
val address: String,
@Json(name = "TelDomowy")
val homePhone: String?,
@Json(name = "TelKomorkowy")
val cellPhone: String?,
@Json(name = "TelSluzbowy")
val workPhone: String?,
@Json(name = "Email")
val email: String,
@Json(name = "FullName")
val fullName: String,
@Json(name = "Telefon")
val phone: String
)

View file

@ -1,8 +1,84 @@
package io.github.wulkanowy.sdk.scrapper.student
class StudentInfo {
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import java.util.Date
lateinit var student: Student
@JsonClass(generateAdapter = true)
data class StudentInfo(
var family: List<FamilyMember> = emptyList()
}
@Json(name = "Imie")
val name: String,
@Json(name = "Imie2")
val middleName: String,
@Json(name = "NumerDokumentu")
val idNumber: Int?,
@Json(name = "Nazwisko")
val lastName: String,
@Json(name = "DataUrodzenia")
val birthDate: Date,
@Json(name = "MiejsceUrodzenia")
val birthPlace: String,
@Json(name = "NazwiskoRodowe")
val familyName: String,
@Json(name = "ObywatelstwoPolskie")
val polishCitizenship: Int,
@Json(name = "ImieMatki")
val motherName: String,
@Json(name = "ImieOjca")
val fatherName: String,
@Json(name = "Plec")
val gender: Boolean,
@Json(name = "AdresZamieszkania")
val address: String,
@Json(name = "AdresZameldowania")
val registeredAddress: String,
@Json(name = "AdresKorespondencji")
val correspondenceAddress: String,
@Json(name = "TelDomowy")
val homePhone: String?,
@Json(name = "TelKomorkowy")
val cellPhone: String?,
@Json(name = "Email")
val email: String,
@Json(name = "CzyWidocznyPesel")
val isVisiblePesel: Boolean,
@Json(name = "Opiekun1")
val guardianFirst: StudentGuardian,
@Json(name = "Opiekun2")
val guardianSecond: StudentGuardian,
@Json(name = "UkryteDaneAdresowe")
val hideAddress: Boolean,
@Json(name = "ImieNazwisko")
val fullName: String,
@Json(name = "PosiadaPesel")
val hasPesel: Boolean,
@Json(name = "Polak")
val isPole: Boolean,
@Json(name = "ImieMatkiIOjca")
val motherAndFatherNames: String
)

View file

@ -1,135 +1,125 @@
package io.github.wulkanowy.sdk.scrapper.student
import io.github.wulkanowy.sdk.scrapper.BaseLocalTest
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test
@Ignore // TODO: implement this in new student
class StudentInfoTest : BaseLocalTest() {
private val info by lazy {
// runBlocking { getStudentRepo(StudentInfoTest::class.java, "UczenDanePodstawowe.html").getStudentInfo() }
StudentInfo()
runBlocking { getStudentRepo(StudentInfoTest::class.java, "Uczen.json").getStudentInfo() }
}
@Test
fun getStudentFirstNameTest() {
assertEquals("Maria", info.student.firstName)
assertEquals("Maria", info.name)
}
@Test
fun getStudentSurnameTest() {
assertEquals("Kamińska", info.student.surname)
assertEquals("Kamińska", info.lastName)
}
@Test
fun getStudentSecondName() {
assertEquals("Aneta", info.student.secondName)
assertEquals("Aneta", info.middleName)
}
@Test
fun getStudentNameTest() {
assertEquals("Maria Aneta Kamińska", info.student.fullName)
assertEquals("Maria Aneta Kamińska", info.fullName)
}
@Test
fun getStudentBirthDateTest() {
assertEquals(getDate(1970, 1, 1), info.student.birthDate)
assertEquals(getDate(1970, 1, 1), info.birthDate)
}
@Test
fun getStudentBirthPlaceTest() {
assertEquals("Warszawa", info.student.birthPlace)
}
@Test
fun getStudentPeselTest() {
assertEquals("12345678900", info.student.pesel)
assertEquals("Warszawa", info.birthPlace)
}
@Test
fun getStudentGenderTest() {
assertEquals("Kobieta", info.student.gender)
assertEquals(false, info.gender)
}
@Test
fun isStudentPolishCitizenshipTest() {
assertEquals("1", info.student.polishCitizenship)
assertEquals(1, info.polishCitizenship)
}
@Test
fun getStudentFamilyNameTest() {
assertEquals("Nowak", info.student.familyName)
assertEquals("Nowak", info.familyName)
}
@Test
fun getStudentParentsNames() {
assertEquals("Gabriela, Kamil", info.student.parentsNames)
assertEquals("Magdalena, Dawid", info.motherAndFatherNames)
assertEquals("Magdalena", info.motherName)
assertEquals("Dawid", info.fatherName)
}
@Test
fun getBasicAddressTest() {
assertEquals("ul. Sportowa 16, 00-123 Warszawa", info.student.address)
assertEquals("ul. Sportowa 16, 00-123 Warszawa", info.address)
}
@Test
fun getBasicRegisteredAddressTest() {
assertEquals("ul. Sportowa 17, 00-123 Warszawa", info.student.registeredAddress)
assertEquals("ul. Sportowa 17, 00-123 Warszawa", info.registeredAddress)
}
@Test
fun getBasicCorrespondenceAddressTest() {
assertEquals("ul. Sportowa 18, 00-123 Warszawa", info.student.correspondenceAddress)
assertEquals("ul. Sportowa 18, 00-123 Warszawa", info.correspondenceAddress)
}
@Test
fun getContactPhoneNumberTest() {
assertEquals("005554433", info.student.phoneNumber)
assertEquals("005554433", info.homePhone)
}
@Test
fun getContactCellPhoneNumberTest() {
assertEquals("555444333", info.student.cellPhoneNumber)
assertEquals("555444333", info.cellPhone)
}
@Test
fun getContactEmailTest() {
assertEquals("wulkanowy@example.null", info.student.email)
}
@Test
fun getFamilyMembers() {
assertEquals(2, info.family.size)
assertEquals("wulkanowy@example.null", info.email)
}
@Test
fun getNameTest() {
assertEquals("Marianna Pająk", info.family[0].fullName)
assertEquals("Dawid Świątek", info.family[1].fullName)
assertEquals("Marianna Pająk", info.guardianFirst.fullName)
assertEquals("Dawid Świątek", info.guardianSecond.fullName)
}
@Test
fun getKinshipTest() {
assertEquals("matka", info.family[0].kinship)
assertEquals("ojciec", info.family[1].kinship)
assertEquals("matka", info.guardianFirst.kinship)
assertEquals("ojciec", info.guardianSecond.kinship)
}
@Test
fun getAddressTest() {
assertEquals("ul. Sportowa 16, 00-123 Warszawa", info.family[0].address)
assertEquals("ul. Sportowa 18, 00-123 Warszawa", info.family[1].address)
assertEquals("ul. Sportowa 16, 00-123 Warszawa", info.guardianFirst.address)
assertEquals("ul. Sportowa 18, 00-123 Warszawa", info.guardianSecond.address)
}
@Test
fun getTelephonesTest() {
assertEquals("555111222", info.family[0].phones)
assertEquals("555222111", info.family[1].phones)
assertEquals("555111222", info.guardianFirst.cellPhone)
assertEquals("555222111", info.guardianSecond.cellPhone)
}
@Test
fun getEmailTest() {
assertEquals("wulkanowy@example.null", info.family[0].email)
assertEquals("wulkanowy@example.null", info.family[1].email)
assertEquals("wulkanowy@example.null", info.guardianFirst.email)
assertEquals("wulkanowy@example.null", info.guardianSecond.email)
}
}

View file

@ -0,0 +1,54 @@
{
"data": {
"Imie": "Maria",
"Imie2": "Aneta",
"NumerDokumentu": null,
"Nazwisko": "Kamińska",
"DataUrodzenia": "1970-01-01 00:00:00",
"MiejsceUrodzenia": "Warszawa",
"NazwiskoRodowe": "Nowak",
"ObywatelstwoPolskie": 1,
"ImieMatki": "Magdalena",
"ImieOjca": "Dawid",
"Plec": false,
"AdresZamieszkania": "ul. Sportowa 16, 00-123 Warszawa",
"AdresZameldowania": "ul. Sportowa 17, 00-123 Warszawa",
"AdresKorespondencji": "ul. Sportowa 18, 00-123 Warszawa",
"TelDomowy": "005554433",
"TelKomorkowy": "555444333",
"Email": "wulkanowy@example.null",
"CzyWidocznyPesel": true,
"Opiekun1": {
"Id": 123,
"Imie": "Magdalena",
"Nazwisko": "Pająk",
"StPokrewienstwa": "matka",
"Adres": "ul. Sportowa 16, 00-123 Warszawa",
"TelDomowy": null,
"TelKomorkowy": "555111222",
"TelSluzbowy": null,
"Email": "wulkanowy@example.null",
"FullName": "Marianna Pająk",
"Telefon": "Telefon: 555111222"
},
"Opiekun2": {
"Id": 124,
"Imie": "Dawid",
"Nazwisko": "Świątek",
"StPokrewienstwa": "ojciec",
"Adres": "ul. Sportowa 18, 00-123 Warszawa",
"TelDomowy": null,
"TelKomorkowy": "555222111",
"TelSluzbowy": "",
"Email": "wulkanowy@example.null",
"FullName": "Dawid Świątek",
"Telefon": "Telefon: 555222111"
},
"UkryteDaneAdresowe": false,
"ImieNazwisko": "Maria Aneta Kamińska",
"PosiadaPesel": true,
"Polak": true,
"ImieMatkiIOjca": "Magdalena, Dawid"
},
"success": true
}

View file

@ -1,36 +1,39 @@
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.StudentGender
import io.github.wulkanowy.sdk.pojo.StudentGuardian
import io.github.wulkanowy.sdk.pojo.StudentInfo
import io.github.wulkanowy.sdk.scrapper.toLocalDate
import io.github.wulkanowy.sdk.scrapper.student.StudentGuardian as ScrapperStudentGuardian
import io.github.wulkanowy.sdk.scrapper.student.StudentInfo as ScrapperStudentInfo
fun ScrapperStudentInfo.mapStudent() = StudentInfo(
student = StudentInfo.Student(
fullName = student.fullName,
address = student.address,
birthDate = student.birthDate.toLocalDate(),
birthPlace = student.birthPlace,
cellPhoneNumber = student.cellPhoneNumber,
correspondenceAddress = student.correspondenceAddress,
email = student.email,
familyName = student.familyName,
firstName = student.firstName,
gender = student.gender,
parentsNames = student.parentsNames,
pesel = student.pesel,
phoneNumber = student.phoneNumber,
polishCitizenship = student.polishCitizenship,
registeredAddress = student.registeredAddress,
secondName = student.secondName,
surname = student.surname
),
family = family.map {
StudentInfo.FamilyMember(
fullName = it.fullName,
email = it.email,
address = it.address,
kinship = it.kinship,
phones = it.phones
)
}
fullName = fullName,
address = address,
birthDate = birthDate.toLocalDate(),
birthPlace = birthPlace,
cellPhoneNumber = cellPhone.orEmpty(),
correspondenceAddress = correspondenceAddress,
email = email,
familyName = familyName,
firstName = name,
gender = if (gender) StudentGender.MALE else StudentGender.FEMALE,
parentsNames = motherAndFatherNames,
phoneNumber = homePhone.orEmpty(),
hasPolishCitizenship = polishCitizenship == 1,
registeredAddress = registeredAddress,
secondName = middleName,
surname = lastName,
guardians = listOf(
guardianFirst.toFamilyMember(),
guardianSecond.toFamilyMember()
)
)
private fun ScrapperStudentGuardian.toFamilyMember() = StudentGuardian(
fullName = fullName,
email = email,
address = address,
kinship = kinship,
phones = phone
)

View file

@ -3,34 +3,34 @@ package io.github.wulkanowy.sdk.pojo
import java.time.LocalDate
data class StudentInfo(
val student: Student,
val family: List<FamilyMember>
) {
data class Student(
val fullName: String,
val firstName: String,
val secondName: String,
val surname: String,
val birthDate: LocalDate,
val birthPlace: String,
val pesel: String,
val gender: String,
val polishCitizenship: String,
val familyName: String,
val parentsNames: String,
val address: String,
val registeredAddress: String,
val correspondenceAddress: String,
val phoneNumber: String,
val cellPhoneNumber: String,
val email: String
)
val fullName: String,
val firstName: String,
val secondName: String,
val surname: String,
val birthDate: LocalDate,
val birthPlace: String,
val gender: StudentGender,
val hasPolishCitizenship: Boolean,
val familyName: String,
val parentsNames: String,
val address: String,
val registeredAddress: String,
val correspondenceAddress: String,
val phoneNumber: String,
val cellPhoneNumber: String,
val email: String,
val guardians: List<StudentGuardian>
)
data class FamilyMember(
val fullName: String,
val kinship: String,
val address: String,
val phones: String,
val email: String
)
data class StudentGuardian(
val fullName: String,
val kinship: String,
val address: String,
val phones: String,
val email: String
)
enum class StudentGender {
MALE,
FEMALE
}