diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt index 3f7d650a..5bf302e3 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt @@ -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() } diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/messages/Mailbox.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/messages/Mailbox.kt index 82b63581..d828404d 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/messages/Mailbox.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/messages/Mailbox.kt @@ -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 = "", ) diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/MessagesRepository.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/MessagesRepository.kt index 5a36f77b..3c57f7e8 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/MessagesRepository.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/repository/MessagesRepository.kt @@ -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 { - return api.getMailboxes() + return api.getMailboxes().map { + it.toRecipient() + .parseName() + .toMailbox() + } } suspend fun getRecipients(mailboxKey: String): List { diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt index 4ca1bb08..6a72d3f2 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/messages/MessagesTest.kt @@ -18,7 +18,7 @@ class MessagesTest : BaseLocalTest() { } @Test - fun getRecipients() = runTest{ + fun getRecipients() = runTest { with(server) { enqueue("Adresaci.json") start(3000) diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/MailboxesMapper.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/MailboxesMapper.kt index 60282ef2..610c800c 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/MailboxesMapper.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/MailboxesMapper.kt @@ -9,6 +9,8 @@ fun List.mapMailboxes(): List { SdkMailbox( globalKey = it.globalKey, name = it.name, + schoolNameShort = it.schoolNameShort, + studentName = it.studentName, ) } } diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/RecipientMapper.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/RecipientMapper.kt index 75069c12..974a716f 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/RecipientMapper.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/RecipientMapper.kt @@ -9,6 +9,8 @@ fun List.mapRecipients() = map { Recipient( name = it.name, mailboxGlobalKey = it.mailboxGlobalKey, + schoolNameShort = it.schoolNameShort, + studentName = it.studentName, ) } @@ -30,6 +32,8 @@ fun List.mapFromMobileToRecipients() = map { Recipient( mailboxGlobalKey = it.loginId.toString(), name = it.name, + schoolNameShort = "", + studentName = "", ) } @@ -37,5 +41,7 @@ fun List.mapRecipients(reportingUnitId: Int) = map { Recipient( name = "${it.name} ${it.surname}", mailboxGlobalKey = reportingUnitId.toString(), + schoolNameShort = "", + studentName = "", ) } diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Mailbox.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Mailbox.kt index f69210bb..c66607b8 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Mailbox.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Mailbox.kt @@ -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, ) diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Recipient.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Recipient.kt index ae7024e5..1d16805e 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Recipient.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Recipient.kt @@ -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, )