balakhonov_danila_lab_3 #140

Merged
Alexey merged 16 commits from balakhonov_danila_lab_3 into main 2024-11-25 21:18:44 +04:00
4 changed files with 31 additions and 2 deletions
Showing only changes of commit 54157ec2bf - Show all commits

View File

@ -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;

View 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}");
}
}
}
}

View File

@ -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();

View File

@ -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: