mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 21:52:44 +01:00
[API] Include device object in each request.
This commit is contained in:
parent
d5ae4b7ec9
commit
1035e411ab
@ -55,14 +55,9 @@ class SzkolnyApi(val app: App) {
|
|||||||
api = retrofit.create()
|
api = retrofit.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEvents(profiles: List<Profile>, notifications: List<Notification>, blacklistedIds: List<Long>): List<EventFull> {
|
private fun getDevice() = run {
|
||||||
val teams = app.db.teamDao().allNow
|
|
||||||
|
|
||||||
val response = api.serverSync(ServerSyncRequest(
|
|
||||||
deviceId = app.deviceId,
|
|
||||||
device = run {
|
|
||||||
val config = app.config
|
val config = app.config
|
||||||
val device = ServerSyncRequest.Device(
|
val device = ApiRequest.Device(
|
||||||
osType = "Android",
|
osType = "Android",
|
||||||
osVersion = Build.VERSION.RELEASE,
|
osVersion = Build.VERSION.RELEASE,
|
||||||
hardware = "${Build.MANUFACTURER} ${Build.MODEL}",
|
hardware = "${Build.MANUFACTURER} ${Build.MODEL}",
|
||||||
@ -80,7 +75,14 @@ class SzkolnyApi(val app: App) {
|
|||||||
device
|
device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
|
fun getEvents(profiles: List<Profile>, notifications: List<Notification>, blacklistedIds: List<Long>): List<EventFull> {
|
||||||
|
val teams = app.db.teamDao().allNow
|
||||||
|
|
||||||
|
val response = api.serverSync(ServerSyncRequest(
|
||||||
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
userCodes = profiles.map { it.userCode },
|
userCodes = profiles.map { it.userCode },
|
||||||
users = profiles.mapNotNull { profile ->
|
users = profiles.mapNotNull { profile ->
|
||||||
val config = app.config.getFor(profile.id)
|
val config = app.config.getFor(profile.id)
|
||||||
@ -131,6 +133,7 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
return api.shareEvent(EventShareRequest(
|
return api.shareEvent(EventShareRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
sharedByName = event.sharedByName,
|
sharedByName = event.sharedByName,
|
||||||
shareTeamCode = team.code,
|
shareTeamCode = team.code,
|
||||||
event = event
|
event = event
|
||||||
@ -142,6 +145,7 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
return api.shareEvent(EventShareRequest(
|
return api.shareEvent(EventShareRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
sharedByName = event.sharedByName,
|
sharedByName = event.sharedByName,
|
||||||
unshareTeamCode = team.code,
|
unshareTeamCode = team.code,
|
||||||
eventId = event.id
|
eventId = event.id
|
||||||
@ -154,8 +158,9 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
fun pairBrowser(browserId: String?, pairToken: String?, onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
fun pairBrowser(browserId: String?, pairToken: String?, onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
||||||
val response = api.webPush(WebPushRequest(
|
val response = api.webPush(WebPushRequest(
|
||||||
action = "pairBrowser",
|
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
|
action = "pairBrowser",
|
||||||
browserId = browserId,
|
browserId = browserId,
|
||||||
pairToken = pairToken
|
pairToken = pairToken
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
@ -170,8 +175,9 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
fun listBrowsers(onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
fun listBrowsers(onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
||||||
val response = api.webPush(WebPushRequest(
|
val response = api.webPush(WebPushRequest(
|
||||||
action = "listBrowsers",
|
deviceId = app.deviceId,
|
||||||
deviceId = app.deviceId
|
device = getDevice(),
|
||||||
|
action = "listBrowsers"
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
|
|
||||||
return response?.data?.browsers ?: emptyList()
|
return response?.data?.browsers ?: emptyList()
|
||||||
@ -179,8 +185,9 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
fun unpairBrowser(browserId: String): List<WebPushResponse.Browser> {
|
fun unpairBrowser(browserId: String): List<WebPushResponse.Browser> {
|
||||||
val response = api.webPush(WebPushRequest(
|
val response = api.webPush(WebPushRequest(
|
||||||
action = "unpairBrowser",
|
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
|
action = "unpairBrowser",
|
||||||
browserId = browserId
|
browserId = browserId
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
|
|
||||||
@ -190,6 +197,7 @@ class SzkolnyApi(val app: App) {
|
|||||||
fun errorReport(errors: List<ErrorReportRequest.Error>): ApiResponse<Nothing>? {
|
fun errorReport(errors: List<ErrorReportRequest.Error>): ApiResponse<Nothing>? {
|
||||||
return api.errorReport(ErrorReportRequest(
|
return api.errorReport(ErrorReportRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
appVersion = BuildConfig.VERSION_NAME,
|
appVersion = BuildConfig.VERSION_NAME,
|
||||||
errors = errors
|
errors = errors
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
@ -198,6 +206,7 @@ class SzkolnyApi(val app: App) {
|
|||||||
fun unregisterAppUser(userCode: String): ApiResponse<Nothing>? {
|
fun unregisterAppUser(userCode: String): ApiResponse<Nothing>? {
|
||||||
return api.appUser(AppUserRequest(
|
return api.appUser(AppUserRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
|
device = getDevice(),
|
||||||
userCode = userCode
|
userCode = userCode
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2020-1-20.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
||||||
|
|
||||||
|
open class ApiRequest(
|
||||||
|
open val deviceId: String,
|
||||||
|
open val device: Device? = null
|
||||||
|
) {
|
||||||
|
data class Device(
|
||||||
|
val osType: String,
|
||||||
|
val osVersion: String,
|
||||||
|
val hardware: String,
|
||||||
|
val pushToken: String?,
|
||||||
|
val appVersion: String,
|
||||||
|
val appType: String,
|
||||||
|
val appVersionCode: Int,
|
||||||
|
val syncInterval: Int
|
||||||
|
)
|
||||||
|
}
|
@ -5,8 +5,9 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
||||||
|
|
||||||
data class AppUserRequest(
|
data class AppUserRequest(
|
||||||
val action: String = "unregister",
|
override val deviceId: String,
|
||||||
|
override val device: Device? = null,
|
||||||
|
|
||||||
val deviceId: String,
|
val action: String = "unregister",
|
||||||
val userCode: String
|
val userCode: String
|
||||||
)
|
) : ApiRequest(deviceId, device)
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
||||||
|
|
||||||
data class ErrorReportRequest(
|
data class ErrorReportRequest(
|
||||||
val deviceId: String,
|
override val deviceId: String,
|
||||||
|
override val device: Device? = null,
|
||||||
|
|
||||||
val appVersion: String,
|
val appVersion: String,
|
||||||
val errors: List<Error>
|
val errors: List<Error>
|
||||||
) {
|
) : ApiRequest(deviceId, device) {
|
||||||
data class Error(
|
data class Error(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val tag: String,
|
val tag: String,
|
||||||
|
@ -7,9 +7,10 @@ package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
|||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
|
|
||||||
data class EventShareRequest (
|
data class EventShareRequest (
|
||||||
|
override val deviceId: String,
|
||||||
|
override val device: Device? = null,
|
||||||
|
|
||||||
val action: String = "event",
|
val action: String = "event",
|
||||||
val deviceId: String,
|
|
||||||
|
|
||||||
val sharedByName: String,
|
val sharedByName: String,
|
||||||
val shareTeamCode: String? = null,
|
val shareTeamCode: String? = null,
|
||||||
@ -18,4 +19,4 @@ data class EventShareRequest (
|
|||||||
|
|
||||||
val eventId: Long? = null,
|
val eventId: Long? = null,
|
||||||
val event: EventFull? = null
|
val event: EventFull? = null
|
||||||
)
|
) : ApiRequest(deviceId, device)
|
||||||
|
@ -5,26 +5,14 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
||||||
|
|
||||||
data class ServerSyncRequest(
|
data class ServerSyncRequest(
|
||||||
|
override val deviceId: String,
|
||||||
val deviceId: String,
|
override val device: Device? = null,
|
||||||
val device: Device? = null,
|
|
||||||
|
|
||||||
val userCodes: List<String>,
|
val userCodes: List<String>,
|
||||||
val users: List<User>? = null,
|
val users: List<User>? = null,
|
||||||
|
|
||||||
val notifications: List<Notification>? = null
|
val notifications: List<Notification>? = null
|
||||||
) {
|
) : ApiRequest(deviceId, device) {
|
||||||
data class Device(
|
|
||||||
val osType: String,
|
|
||||||
val osVersion: String,
|
|
||||||
val hardware: String,
|
|
||||||
val pushToken: String?,
|
|
||||||
val appVersion: String,
|
|
||||||
val appType: String,
|
|
||||||
val appVersionCode: Int,
|
|
||||||
val syncInterval: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class User(
|
data class User(
|
||||||
val userCode: String,
|
val userCode: String,
|
||||||
val studentName: String,
|
val studentName: String,
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
package pl.szczodrzynski.edziennik.data.api.szkolny.request
|
||||||
|
|
||||||
data class WebPushRequest(
|
data class WebPushRequest(
|
||||||
|
override val deviceId: String,
|
||||||
|
override val device: Device? = null,
|
||||||
|
|
||||||
val action: String,
|
val action: String,
|
||||||
val deviceId: String,
|
|
||||||
|
|
||||||
val browserId: String? = null,
|
val browserId: String? = null,
|
||||||
val pairToken: String? = null
|
val pairToken: String? = null
|
||||||
)
|
) : ApiRequest(deviceId, device)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user