balakhonov_danila_lab_3 #140
@ -22,7 +22,7 @@ public class RestaurantController : ControllerBase
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Restaurant?>> 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;
|
||||
|
28
balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs
Normal file
28
balakhonov_danila_lab_3/ApiRestaurant/NetworkSupport.cs
Normal file
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user