diff --git a/Confectionery/ConfectioneryClientApp/APIClient.cs b/Confectionery/ConfectioneryClientApp/APIClient.cs index 77b3094..ede847a 100644 --- a/Confectionery/ConfectioneryClientApp/APIClient.cs +++ b/Confectionery/ConfectioneryClientApp/APIClient.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.ViewModels; +using Newtonsoft.Json; using System.Net.Http.Headers; using System.Text; @@ -8,13 +8,16 @@ namespace ConfectioneryClientApp public class APIClient { private static readonly HttpClient _client = new(); + public static ClientViewModel? Client { get; set; } = null; + public static void Connect(IConfiguration configuration) { _client.BaseAddress = new Uri(configuration["IPAddress"]); _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } + public static T? GetRequest(string requestUrl) { var response = _client.GetAsync(requestUrl); @@ -28,17 +31,19 @@ namespace ConfectioneryClientApp throw new Exception(result); } } + public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = _client.PostAsync(requestUrl, data); + var result = response.Result.Content.ReadAsStringAsync().Result; if (!response.Result.IsSuccessStatusCode) { throw new Exception(result); } } - } } diff --git a/Confectionery/ConfectioneryRestApi/WeatherForecast.cs b/Confectionery/ConfectioneryRestApi/WeatherForecast.cs deleted file mode 100644 index 63fe779..0000000 --- a/Confectionery/ConfectioneryRestApi/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace ConfectioneryRestApi -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -}