NSCv3: delete records from NS properly
This commit is contained in:
parent
87ca7ef6cf
commit
7da84536eb
|
@ -186,7 +186,9 @@ class NSAndroidClientImpl(
|
|||
nsSgvV3.date = null
|
||||
val remoteEntry = nsSgvV3.toRemoteEntry()
|
||||
val identifier = remoteEntry.identifier ?: throw InvalidFormatNightscoutException()
|
||||
val response = api.updateEntry(remoteEntry, identifier)
|
||||
val response =
|
||||
if (nsSgvV3.isValid) api.updateEntry(remoteEntry, identifier)
|
||||
else api.deleteEntry(identifier)
|
||||
if (response.isSuccessful) {
|
||||
return@callWrapper CreateUpdateResponse(
|
||||
response = response.code(),
|
||||
|
@ -312,7 +314,9 @@ class NSAndroidClientImpl(
|
|||
nsTreatment.date = null
|
||||
val remoteTreatment = nsTreatment.toRemoteTreatment() ?: throw InvalidFormatNightscoutException()
|
||||
val identifier = remoteTreatment.identifier ?: throw InvalidFormatNightscoutException()
|
||||
val response = api.updateTreatment(remoteTreatment, identifier)
|
||||
val response =
|
||||
if (nsTreatment.isValid) api.updateTreatment(remoteTreatment, identifier)
|
||||
else api.deleteTreatment(identifier)
|
||||
if (response.isSuccessful) {
|
||||
return@callWrapper CreateUpdateResponse(
|
||||
response = response.code(),
|
||||
|
@ -388,7 +392,10 @@ class NSAndroidClientImpl(
|
|||
override suspend fun updateFood(nsFood: NSFood): CreateUpdateResponse = callWrapper(dispatcher) {
|
||||
|
||||
val remoteFood = nsFood.toRemoteFood()
|
||||
val response = api.updateFood(remoteFood)
|
||||
val identifier = nsFood.identifier ?: throw InvalidFormatNightscoutException()
|
||||
val response =
|
||||
if (nsFood.isValid) api.updateFood(remoteFood, identifier)
|
||||
else api.deleteFood(identifier)
|
||||
if (response.isSuccessful) {
|
||||
return@callWrapper CreateUpdateResponse(
|
||||
response = response.code(),
|
||||
|
|
|
@ -12,6 +12,7 @@ import info.nightscout.sdk.remotemodel.RemoteTreatment
|
|||
import org.json.JSONObject
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.DELETE
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.PATCH
|
||||
import retrofit2.http.POST
|
||||
|
@ -52,6 +53,9 @@ internal interface NightscoutRemoteService {
|
|||
@PATCH("v3/entries/{identifier}")
|
||||
suspend fun updateEntry(@Body remoteEntry: RemoteEntry, @Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@DELETE("v3/entries/{identifier}")
|
||||
suspend fun deleteEntry(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@GET("v3/treatments")
|
||||
suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Long): Response<NSResponse<List<RemoteTreatment>>>
|
||||
|
||||
|
@ -64,6 +68,9 @@ internal interface NightscoutRemoteService {
|
|||
@PATCH("v3/treatments/{identifier}")
|
||||
suspend fun updateTreatment(@Body remoteTreatment: RemoteTreatment, @Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@DELETE("v3/treatments/{identifier}")
|
||||
suspend fun deleteTreatment(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@POST("v3/devicestatus")
|
||||
suspend fun createDeviceStatus(@Body remoteDeviceStatus: RemoteDeviceStatus): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
|
@ -81,7 +88,10 @@ internal interface NightscoutRemoteService {
|
|||
suspend fun createFood(@Body remoteFood: RemoteFood): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@PATCH("v3/food")
|
||||
suspend fun updateFood(@Body remoteFood: RemoteFood): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
suspend fun updateFood(@Body remoteFood: RemoteFood, @Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@DELETE("v3/food")
|
||||
suspend fun deleteFood(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||
|
||||
@GET("v3/profile?sort\$desc=date&limit=1")
|
||||
suspend fun getLastProfile(): Response<NSResponse<List<JSONObject>>>
|
||||
|
|
Loading…
Reference in a new issue