diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt index 4769e6c3a4..d7bf25eaf7 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt @@ -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(), diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt index 59af887bdd..38e35c3c84 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt @@ -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> + @DELETE("v3/entries/{identifier}") + suspend fun deleteEntry(@Path("identifier") identifier: String): Response> + @GET("v3/treatments") suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Long): Response>> @@ -64,6 +68,9 @@ internal interface NightscoutRemoteService { @PATCH("v3/treatments/{identifier}") suspend fun updateTreatment(@Body remoteTreatment: RemoteTreatment, @Path("identifier") identifier: String): Response> + @DELETE("v3/treatments/{identifier}") + suspend fun deleteTreatment(@Path("identifier") identifier: String): Response> + @POST("v3/devicestatus") suspend fun createDeviceStatus(@Body remoteDeviceStatus: RemoteDeviceStatus): Response> @@ -81,7 +88,10 @@ internal interface NightscoutRemoteService { suspend fun createFood(@Body remoteFood: RemoteFood): Response> @PATCH("v3/food") - suspend fun updateFood(@Body remoteFood: RemoteFood): Response> + suspend fun updateFood(@Body remoteFood: RemoteFood, @Path("identifier") identifier: String): Response> + + @DELETE("v3/food") + suspend fun deleteFood(@Path("identifier") identifier: String): Response> @GET("v3/profile?sort\$desc=date&limit=1") suspend fun getLastProfile(): Response>>