using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; namespace BlazingPizza.Client { public class OrdersClient { private readonly HttpClient httpClient; public OrdersClient(HttpClient httpClient) { this.httpClient = httpClient; } public async Task> GetOrders() => await httpClient.GetFromJsonAsync>("orders"); public async Task GetOrder(int orderId) => await httpClient.GetFromJsonAsync($"orders/{orderId}"); public async Task PlaceOrder(Order order) { var response = await httpClient.PostAsJsonAsync("orders", order); response.EnsureSuccessStatusCode(); var orderId = await response.Content.ReadFromJsonAsync(); return orderId; } public async Task SubscribeToNotifications(NotificationSubscription subscription) { var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription); response.EnsureSuccessStatusCode(); } } }