Add deleting messages (#14)
This commit is contained in:
parent
1084335727
commit
ee999bbe93
7 changed files with 78 additions and 4 deletions
|
@ -254,6 +254,8 @@ class Api {
|
|||
|
||||
fun sendMessage(subject: String, content: String, recipients: List<Recipient>) = messages.sendMessage(subject, content, recipients)
|
||||
|
||||
fun deleteMessages(messages: List<Pair<Int, Int>>) = this.messages.deleteMessages(messages)
|
||||
|
||||
fun getTimetable(startDate: LocalDate, endDate: LocalDate? = null) =
|
||||
if (useNewStudent) student.getTimetable(startDate, endDate) else snp.getTimetable(startDate, endDate)
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package io.github.wulkanowy.api.messages
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class DeleteMessageRequest(
|
||||
|
||||
@SerializedName("Id")
|
||||
val messageId: Int,
|
||||
|
||||
@SerializedName("Folder")
|
||||
val folderId: Int
|
||||
|
||||
)
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.wulkanowy.api.repository
|
||||
|
||||
import io.github.wulkanowy.api.getScriptParam
|
||||
import io.github.wulkanowy.api.messages.DeleteMessageRequest
|
||||
import io.github.wulkanowy.api.messages.Message
|
||||
import io.github.wulkanowy.api.messages.Recipient
|
||||
import io.github.wulkanowy.api.messages.ReportingUnit
|
||||
|
@ -87,6 +88,22 @@ class MessagesRepository(private val api: MessagesService) {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteMessages(messages: List<Pair<Int, Int>>): Single<Boolean> {
|
||||
return api.getStart().flatMap { res ->
|
||||
api.deleteMessage(
|
||||
messages.map { (messageId, folderId) ->
|
||||
DeleteMessageRequest(
|
||||
messageId = messageId,
|
||||
folderId = folderId
|
||||
)
|
||||
},
|
||||
getScriptParam("antiForgeryToken", res),
|
||||
getScriptParam("appGuid", res),
|
||||
getScriptParam("version", res)
|
||||
).map { it.success }
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.normalizeRecipient(): String {
|
||||
return this.substringBeforeLast("-").substringBefore(" [").substringBeforeLast(" (").trim()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.wulkanowy.api.service
|
||||
|
||||
import io.github.wulkanowy.api.ApiResponse
|
||||
import io.github.wulkanowy.api.messages.DeleteMessageRequest
|
||||
import io.github.wulkanowy.api.messages.Message
|
||||
import io.github.wulkanowy.api.messages.Recipient
|
||||
import io.github.wulkanowy.api.messages.ReportingUnit
|
||||
|
@ -57,4 +58,12 @@ interface MessagesService {
|
|||
@Header("X-V-AppGuid") appGuid: String,
|
||||
@Header("X-V-AppVersion") appVersion: String
|
||||
): Single<ApiResponse<SentMessage>>
|
||||
|
||||
@POST("Wiadomosc.mvc/UsunWiadomosc")
|
||||
fun deleteMessage(
|
||||
@Body deleteMessageRequests: List<DeleteMessageRequest>,
|
||||
@Header("X-V-RequestVerificationToken") token: String,
|
||||
@Header("X-V-AppGuid") appGuid: String,
|
||||
@Header("X-V-AppVersion") appVersion: String
|
||||
): Single<ApiResponse<Nothing>>
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.wulkanowy.api
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonParser
|
||||
import io.github.wulkanowy.api.grades.DateDeserializer
|
||||
import io.github.wulkanowy.api.grades.GradeDate
|
||||
import io.github.wulkanowy.api.interceptor.ErrorInterceptor
|
||||
|
@ -23,6 +24,7 @@ import retrofit2.converter.scalars.ScalarsConverterFactory
|
|||
abstract class BaseLocalTest : BaseTest() {
|
||||
|
||||
val server = MockWebServer()
|
||||
val jsonParser = JsonParser()
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.github.wulkanowy.api.messages
|
||||
|
||||
import com.google.gson.JsonParser
|
||||
import io.github.wulkanowy.api.BaseLocalTest
|
||||
import io.github.wulkanowy.api.repository.MessagesRepository
|
||||
import io.github.wulkanowy.api.service.MessagesService
|
||||
|
@ -157,10 +156,32 @@ class MessagesTest : BaseLocalTest() {
|
|||
|
||||
server.takeRequest()
|
||||
|
||||
val parser = JsonParser()
|
||||
val expected = parser.parse(MessagesTest::class.java.getResource("NowaWiadomosc.json").readText())
|
||||
val expected = jsonParser.parse(MessagesTest::class.java.getResource("NowaWiadomosc.json").readText())
|
||||
val request = server.takeRequest()
|
||||
val actual = parser.parse(request.body.readUtf8())
|
||||
val actual = jsonParser.parse(request.body.readUtf8())
|
||||
|
||||
assertEquals(expected, actual)
|
||||
assertEquals(
|
||||
"lX9xvk-OBA0VmHrNIFcQp2xVBZhza9tJ1QbYVKXGM3lFUr0a-OTDo5xUSQ70ROYKf6ICZ1LSXCfDAURoCmDZ-OEedW8IKtyF1s63HyWKxbmHaP-vsVCsGlN6zRHwx1r4h",
|
||||
request.getHeader("X-V-RequestVerificationToken")
|
||||
)
|
||||
assertEquals("877c4a726ad61667f4e2237f0cf6307a", request.getHeader("X-V-AppGuid"))
|
||||
assertEquals("19.02.0001.32324", request.getHeader("X-V-AppVersion"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteMessageTest() {
|
||||
server.enqueue(MockResponse().setBody(MessagesTest::class.java.getResource("Start.html").readText()))
|
||||
server.enqueue(MockResponse().setBody("{\"success\": true}"))
|
||||
server.start(3000)
|
||||
|
||||
assertEquals(api.deleteMessages(listOf(Pair(74, 1), Pair(69, 2))).blockingGet(), true)
|
||||
|
||||
server.takeRequest()
|
||||
|
||||
val expected = jsonParser.parse(MessagesTest::class.java.getResource("UsunWiadomosc.json").readText())
|
||||
val request = server.takeRequest()
|
||||
val actual = jsonParser.parse(request.body.readUtf8())
|
||||
|
||||
assertEquals(expected, actual)
|
||||
assertEquals(
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
[
|
||||
{
|
||||
"Id": 74,
|
||||
"Folder": 1
|
||||
},
|
||||
{
|
||||
"Id": 69,
|
||||
"Folder": 2
|
||||
}
|
||||
]
|
Loading…
Reference in a new issue