Parse mailboxes names

This commit is contained in:
Mikołaj Pich 2022-08-15 17:20:10 +02:00
parent cf29b966d6
commit c3db2cdc3d
8 changed files with 43 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package io.github.wulkanowy.sdk.scrapper
import io.github.wulkanowy.sdk.scrapper.messages.Mailbox
import io.github.wulkanowy.sdk.scrapper.messages.Recipient
import io.github.wulkanowy.sdk.scrapper.messages.RecipientType
import org.jsoup.Jsoup.parse
@ -87,4 +88,15 @@ fun Recipient.parseName(): Recipient {
)
}
fun Mailbox.toRecipient() = Recipient(
mailboxGlobalKey = globalKey,
name = name,
)
fun Recipient.toMailbox() = Mailbox(
globalKey = mailboxGlobalKey,
name = name,
userType = -1,
)
fun String.capitalise() = replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.sdk.scrapper.messages
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
data class Mailbox(
@ -14,4 +15,13 @@ data class Mailbox(
@SerialName("typUzytkownika")
val userType: Int,
@Transient
val type: RecipientType = RecipientType.UNKNOWN,
@Transient
val studentName: String = "",
@Transient
val schoolNameShort: String = "",
)

View file

@ -6,12 +6,19 @@ import io.github.wulkanowy.sdk.scrapper.messages.MessageMeta
import io.github.wulkanowy.sdk.scrapper.messages.Recipient
import io.github.wulkanowy.sdk.scrapper.messages.SendMessageRequest
import io.github.wulkanowy.sdk.scrapper.normalizeRecipients
import io.github.wulkanowy.sdk.scrapper.parseName
import io.github.wulkanowy.sdk.scrapper.service.MessagesService
import io.github.wulkanowy.sdk.scrapper.toMailbox
import io.github.wulkanowy.sdk.scrapper.toRecipient
class MessagesRepository(private val api: MessagesService) {
suspend fun getMailboxes(): List<Mailbox> {
return api.getMailboxes()
return api.getMailboxes().map {
it.toRecipient()
.parseName()
.toMailbox()
}
}
suspend fun getRecipients(mailboxKey: String): List<Recipient> {

View file

@ -18,7 +18,7 @@ class MessagesTest : BaseLocalTest() {
}
@Test
fun getRecipients() = runTest{
fun getRecipients() = runTest {
with(server) {
enqueue("Adresaci.json")
start(3000)

View file

@ -9,6 +9,8 @@ fun List<ScrapperMailbox>.mapMailboxes(): List<Mailbox> {
SdkMailbox(
globalKey = it.globalKey,
name = it.name,
schoolNameShort = it.schoolNameShort,
studentName = it.studentName,
)
}
}

View file

@ -9,6 +9,8 @@ fun List<ScrapperRecipient>.mapRecipients() = map {
Recipient(
name = it.name,
mailboxGlobalKey = it.mailboxGlobalKey,
schoolNameShort = it.schoolNameShort,
studentName = it.studentName,
)
}
@ -30,6 +32,8 @@ fun List<MobileRecipient>.mapFromMobileToRecipients() = map {
Recipient(
mailboxGlobalKey = it.loginId.toString(),
name = it.name,
schoolNameShort = "",
studentName = "",
)
}
@ -37,5 +41,7 @@ fun List<Teacher>.mapRecipients(reportingUnitId: Int) = map {
Recipient(
name = "${it.name} ${it.surname}",
mailboxGlobalKey = reportingUnitId.toString(),
schoolNameShort = "",
studentName = "",
)
}

View file

@ -3,4 +3,6 @@ package io.github.wulkanowy.sdk.pojo
data class Mailbox(
val globalKey: String,
val name: String,
val studentName: String,
val schoolNameShort: String,
)

View file

@ -3,4 +3,6 @@ package io.github.wulkanowy.sdk.pojo
data class Recipient(
val mailboxGlobalKey: String,
val name: String,
val studentName: String,
val schoolNameShort: String,
)