From 54157ec2bf913efa1577c3e5ce5f1eaac861f5d9 Mon Sep 17 00:00:00 2001 From: mfnefd Date: Mon, 4 Nov 2024 00:42:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=87=D1=82=D0=BE=D0=B1=20=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D1=8C?= =?UTF-8?q?=20=D1=87=D1=82=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B8=D1=81=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=82=20=D0=B2=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RestaurantController.cs | 2 +- .../ApiRestaurant/NetworkSupport.cs | 28 +++++++++++++++++++ .../ApiRestaurant/Program.cs | 1 + balakhonov_danila_lab_3/docker-compose.yaml | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs diff --git a/balakhonov_danila_lab_3/ApiRestaurant/Controllers/RestaurantController.cs b/balakhonov_danila_lab_3/ApiRestaurant/Controllers/RestaurantController.cs index 0d1a6de..2984cb8 100644 --- a/balakhonov_danila_lab_3/ApiRestaurant/Controllers/RestaurantController.cs +++ b/balakhonov_danila_lab_3/ApiRestaurant/Controllers/RestaurantController.cs @@ -22,7 +22,7 @@ public class RestaurantController : ControllerBase [HttpGet("{id}")] public async Task> GetOne(Guid id) { var restaurant = await _context.Restaurants.FindAsync(id); - if (restaurant == null) return NotFound(); + if (restaurant == null) return NotFound($"Restourant with [id: '{id}'] not found"); var waiters = await WaiterApiClient.GetAllForRestaurant(id); restaurant.Waiters = waiters; return restaurant; diff --git a/balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs b/balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs new file mode 100644 index 0000000..709bb5b --- /dev/null +++ b/balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs @@ -0,0 +1,28 @@ +namespace ApiRestaurant; + +public static class NetworkSupport +{ + public static async Task CheckConnectionAsync(string address) + { + using (var client = new HttpClient()) + { + try + { + var response = await client.GetAsync(address); + + if (response.IsSuccessStatusCode) + { + Console.WriteLine($"Соединение успешно проверено. Статус-код: {response.StatusCode}"); + } + else + { + Console.WriteLine($"Соединение не удалось проверить. Статус-код: {response.StatusCode}"); + } + } + catch (HttpRequestException ex) + { + Console.WriteLine($"Ошибка при проверке соединения: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/balakhonov_danila_lab_3/ApiRestaurant/Program.cs b/balakhonov_danila_lab_3/ApiRestaurant/Program.cs index 8eeab39..39106cb 100644 --- a/balakhonov_danila_lab_3/ApiRestaurant/Program.cs +++ b/balakhonov_danila_lab_3/ApiRestaurant/Program.cs @@ -8,6 +8,7 @@ var waiterApiAddress = Environment.GetEnvironmentVariable("WAITER_API_URL") ?? "http://localhost:4000/waiters/"; WaiterApiClient.Setup(waiterApiAddress); +await NetworkSupport.CheckConnectionAsync(waiterApiAddress); // Add services to the container. builder.Services.AddControllers(); diff --git a/balakhonov_danila_lab_3/docker-compose.yaml b/balakhonov_danila_lab_3/docker-compose.yaml index 8a1d306..21cf9e8 100644 --- a/balakhonov_danila_lab_3/docker-compose.yaml +++ b/balakhonov_danila_lab_3/docker-compose.yaml @@ -2,7 +2,7 @@ services: restaurant_service: build: ./ApiRestaurant/ environment: - WAITER_API_URL: http://localhost:80/waiters/ + WAITER_API_URL: http://waiter_service:4000/waiters/ expose: - 8080 depends_on: