using collAnon.Pub.Shared; using drinkMe.Client.Services.Interfaces; using drinkMe.Shared; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; namespace drinkMe.Client.Services { public class DataService : IDataService { readonly HttpClient HttpClient; public DataService(HttpClient httpClient) { HttpClient = httpClient; } public async Task IsValidDiscountCode(string code) { var result = new WebResult(); var httpResponse = await HttpClient.GetAsync($"api/Drinks/{nameof(IsValidDiscountCode)}?{nameof(code)}={code}"); if (!httpResponse.IsSuccessStatusCode) return result.Invalidate(JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); result.Data = JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); return result; } public async Task GetDrinks() { var result = new WebResult(); var httpResponse = await HttpClient.GetAsync($"api/Drinks/{nameof(GetDrinks)}"); if (!httpResponse.IsSuccessStatusCode) return result.Invalidate(JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); result.Data = JsonSerializer.Deserialize>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); return result; } } }