NSCv3: updateTreatment
This commit is contained in:
parent
0da75f1d69
commit
63215c778a
|
@ -174,6 +174,22 @@ class NSAndroidClientImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun updateTreatment(nsTreatment: NSTreatment): CreateUpdateResponse = callWrapper(dispatcher) {
|
||||
|
||||
val remoteTreatment = nsTreatment.toRemoteTreatment() ?: throw InvalidFormatNightscoutException()
|
||||
val response = api.updateTreatment(remoteTreatment)
|
||||
if (response.isSuccessful) {
|
||||
return@callWrapper CreateUpdateResponse(
|
||||
identifier = response.body()?.result?.identifier ?: throw UnknownResponseNightscoutException(),
|
||||
isDeduplication = response.body()?.result?.isDeduplication ?: false,
|
||||
deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier,
|
||||
lastModified = response.body()?.result?.lastModified
|
||||
)
|
||||
} else {
|
||||
throw TodoNightscoutException() // TODO: react to response errors (offline, ...)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun <T> callWrapper(dispatcher: CoroutineDispatcher, block: suspend () -> T): T =
|
||||
withContext(dispatcher) {
|
||||
retry(
|
||||
|
|
|
@ -20,5 +20,6 @@ interface NSAndroidClient {
|
|||
suspend fun getSgvsNewerThan(from: Long, limit: Long): List<NSSgvV3>
|
||||
suspend fun getTreatmentsModifiedSince(from: Long, limit: Long): List<NSTreatment>
|
||||
suspend fun getDeviceStatusModifiedSince(from: Long): List<RemoteDeviceStatus>
|
||||
suspend fun createTreatment(NsTreatment: NSTreatment): CreateUpdateResponse
|
||||
suspend fun createTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
||||
suspend fun updateTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
||||
}
|
|
@ -15,6 +15,7 @@ import retrofit2.http.Body
|
|||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
|
@ -58,4 +59,7 @@ internal interface NightscoutRemoteService {
|
|||
@POST("v3/treatments")
|
||||
fun createTreatment(@Body remoteTreatment: RemoteTreatment): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@PUT("v3/treatments")
|
||||
fun updateTreatment(@Body remoteTreatment: RemoteTreatment): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue