фикс
This commit is contained in:
parent
2564d27b89
commit
c26ab75741
@ -1,3 +1,5 @@
|
||||
using IceCreamShopApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
@ -5,6 +7,8 @@ builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
|
111
IceCreamShop/IceCreamShopRestApi/Controllers/ShopController.cs
Normal file
111
IceCreamShop/IceCreamShopRestApi/Controllers/ShopController.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using IceCreamShopContracts.BindingModels;
|
||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||
using IceCreamShopContracts.SearchModels;
|
||||
using IceCreamShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IceCreamShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopLogic _shop;
|
||||
|
||||
public ShopController(ILogger<MainController> logger, IShopLogic shop)
|
||||
{
|
||||
_logger = logger;
|
||||
_shop = shop;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ShopViewModel>? GetShops()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _shop.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<ShopViewModel, List<Tuple<string, int>>>? GetShop(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _shop.ReadElement(new ShopSearchModel { Id = shopId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.ShopIceCreams.Select(x => Tuple.Create(x.Value.Item1.IceCreamName, x.Value.Item2)).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина по id={Id}", shopId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shop.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
model.ShopIceCreams = null!;
|
||||
_shop.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shop.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddIceCreamInShop(Tuple<ShopSearchModel, IceCreamViewModel, int> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shop.SupplyIceCreams(model.Item1, model.Item2, model.Item3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления мороженого в магазин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
<ProjectReference Include="..\IceCreamBusinessLogic\IceCreamBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\IceCreamShopContracts\IceCreamShopContracts.csproj" />
|
||||
<ProjectReference Include="..\IceCreamShopDatabaseImplement\IceCreamShopDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\IceCreamShopFileImplement\IceCreamShopFileImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IIceCreamStorage, IceCreamStorage>();
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IIceCreamLogic, IceCreamLogic>();
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
24
IceCreamShop/IceCreamShopRestApi/Shop.xml
Normal file
24
IceCreamShop/IceCreamShopRestApi/Shop.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Shops>
|
||||
<Shop Id="1">
|
||||
<Name>small</Name>
|
||||
<Adress>string</Adress>
|
||||
<OpeningDate>2023-04-12T09:20:34.333Z</OpeningDate>
|
||||
<IceCreamMaxCount>4</IceCreamMaxCount>
|
||||
<ShopIceCreams />
|
||||
</Shop>
|
||||
<Shop Id="2">
|
||||
<Name>small</Name>
|
||||
<Adress>string</Adress>
|
||||
<OpeningDate>2023-04-12T09:20:34.333Z</OpeningDate>
|
||||
<IceCreamMaxCount>4</IceCreamMaxCount>
|
||||
<ShopIceCreams />
|
||||
</Shop>
|
||||
<Shop Id="3">
|
||||
<Name>asd</Name>
|
||||
<Adress>asd</Adress>
|
||||
<OpeningDate>2023-04-07T00:00:00</OpeningDate>
|
||||
<IceCreamMaxCount>4</IceCreamMaxCount>
|
||||
<ShopIceCreams />
|
||||
</Shop>
|
||||
</Shops>
|
Loading…
Reference in New Issue
Block a user