From 3ece117a98f60404ea834985a6e74329c89087e1 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 3 May 2024 20:25:30 +0400 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=84=D0=BE=D0=BB=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/ConfectioneryClientApp/APIClient.cs | 11 ++++++++--- .../ConfectioneryRestApi/WeatherForecast.cs | 13 ------------- 2 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 Confectionery/ConfectioneryRestApi/WeatherForecast.cs 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; } - } -}