Skip to content

Commit

Permalink
Improve Appwrite function response deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
adityaoberai committed Jan 23, 2023
1 parent 95a3731 commit 7aa6245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions SOS/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ private async void SOSButtonClicked(object sender, EventArgs e)

var sosResponse = await client.PostAsync(endpoint, jsonContent);
var sosResponseContent = await sosResponse.Content.ReadAsStringAsync();
var sosResponseData = JsonConvert.DeserializeObject<AppwriteApiResponse>(sosResponseContent);
var sosResponseObject = JsonConvert.DeserializeObject<AppwriteApiResponse>(sosResponseContent); // Complete function response from Appwrite
var sosResponseData = JsonConvert.DeserializeObject<AppwriteResponseData>(sosResponseObject.Response); // Data returned from function

var appwriteFunctionResponse = JsonConvert.DeserializeObject<Dictionary<string, object>>(sosResponseData.Response);
if (Convert.ToBoolean(appwriteFunctionResponse["sos"]))
if (sosResponseData.Sos)
{
await DisplayAlert("Alert", $"Sent SOS Request to {settings.PhoneNumber}", "Ok");
}
Expand Down
6 changes: 6 additions & 0 deletions SOS/Models/AppwriteApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace SOS.Models
{
public class AppwriteResponseData
{
[JsonProperty("sos")]
public bool Sos { get; set; }
}

public class AppwriteApiResponse
{
[JsonProperty("$id")]
Expand Down

0 comments on commit 7aa6245

Please sign in to comment.