Добавил RestApi

This commit is contained in:
Алексей Тихоненков 2024-05-04 21:33:24 +04:00
parent 10ee9301d1
commit d12a62fa3b
12 changed files with 712 additions and 1 deletions

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomDataModels", "Din
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomDatabaseImplement", "DiningRoomDatabaseImplement\DiningRoomDatabaseImplement.csproj", "{348BD2CC-C93D-42E8-A890-FC7807476625}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomBusinessLogic", "DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj", "{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomBusinessLogic", "DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj", "{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomRestApi", "DiningRoomRestApi\DiningRoomRestApi.csproj", "{BE787325-AB78-45A0-AE64-62E46E64248E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.Build.0 = Release|Any CPU
{BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,106 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CardController : Controller
{
private readonly ILogger _logger;
private readonly ICardLogic _logic;
public CardController(ICardLogic logic, ILogger<CardController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public CardViewModel? GetCard(int id)
{
try
{
return _logic.ReadElement(new CardSearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения заказа");
throw;
}
}
/// <summary>
/// Получение карт по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<CardViewModel>? GetCards(int userId)
{
try
{
return _logic.ReadList(new CardSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateCard(CardBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void UpdateCard(CardBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления заказа");
throw;
}
}
[HttpDelete]
public void DeleteCard(CardBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}
}

View File

@ -0,0 +1,98 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ComponentController : Controller
{
private readonly ILogger _logger;
private readonly IComponentLogic _componentLogic;
public ComponentController(IComponentLogic Logic, ILogger<ComponentController> Logger)
{
_logger = Logger;
_componentLogic = Logic;
}
[HttpGet]
public ComponentViewModel? GetComponent(int Id)
{
try
{
return _componentLogic.ReadElement(new ComponentSearchModel
{
Id = Id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта");
throw;
}
}
[HttpGet]
public List<ComponentViewModel>? GetComponents(int? UserId)
{
try
{
return _componentLogic.ReadList(new ComponentSearchModel
{
UserId = UserId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов пользователя с Id = {Id}", UserId);
throw;
}
}
[HttpPost]
public void CreateComponent(ComponentBindingModel Model)
{
try
{
_componentLogic.Create(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания продукта");
throw;
}
}
[HttpPost]
public void UpdateComponent(ComponentBindingModel Model)
{
try
{
_componentLogic.Update(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления продукта");
throw;
}
}
[HttpDelete]
public void DeleteComponent(ComponentBindingModel Model)
{
try
{
_componentLogic.Delete(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления продукта");
throw;
}
}
}
}

View File

@ -0,0 +1,111 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DrinkController : Controller
{
private readonly ILogger _logger;
private readonly IDrinkLogic _DrinkLogic;
public DrinkController(IDrinkLogic Logic, ILogger<DrinkController> Logger)
{
_logger = Logger;
_DrinkLogic = Logic;
}
[HttpGet]
public DrinkViewModel? GetDrink(int Id)
{
try
{
return _DrinkLogic.ReadElement(new DrinkSearchModel
{
Id = Id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения напитка");
throw;
}
}
[HttpGet]
public List<DrinkViewModel>? GetDrinks(int? UserId)
{
try
{
return _DrinkLogic.ReadList(new DrinkSearchModel
{
UserId = UserId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка напитков пользователя с Id = {Id}", UserId);
throw;
}
}
[HttpPost]
public void ConnectCardDrink(int CardId, int DrinkId)
{
try
{
_DrinkLogic.ConnectCardDrink(new DrinkBindingModel { Id = DrinkId, CardId = CardId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка связывания заявки со сборкой");
throw;
}
}
[HttpPost]
public void CreateDrink(DrinkBindingModel Model)
{
try
{
_DrinkLogic.Create(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания напитка");
throw;
}
}
[HttpPost]
public void UpdateDrink(DrinkBindingModel Model)
{
try
{
_DrinkLogic.Update(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления напитка");
throw;
}
}
[HttpDelete]
public void DeleteDrink(DrinkBindingModel Model)
{
try
{
_DrinkLogic.Delete(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления напитка");
throw;
}
}
}
}

View File

@ -0,0 +1,101 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using DiningRoomDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class OrderController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _logic;
public OrderController(IOrderLogic logic, ILogger<OrderController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public OrderViewModel? GetOrder(int id)
{
try
{
return _logic.ReadElement(new OrderSearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения заказа");
throw;
}
}
/// <summary>
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<OrderViewModel>? GetOrders(int? userId)
{
try
{
return _logic.ReadList(new OrderSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void UpdateOrder(OrderBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления заказа");
throw;
}
}
[HttpDelete]
public void DeleteOrder(OrderBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}
}

View File

@ -0,0 +1,98 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ProductController : Controller
{
private readonly ILogger _logger;
private readonly IProductLogic _productLogic;
public ProductController(IProductLogic Logic, ILogger<ProductController> Logger)
{
_logger = Logger;
_productLogic = Logic;
}
[HttpGet]
public ProductViewModel? GetProduct(int Id)
{
try
{
return _productLogic.ReadElement(new ProductSearchModel
{
Id = Id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения блюда");
throw;
}
}
[HttpGet]
public List<ProductViewModel>? GetProducts(int? UserId)
{
try
{
return _productLogic.ReadList(new ProductSearchModel
{
UserId = UserId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка блюд пользователя с Id = {Id}", UserId);
throw;
}
}
[HttpPost]
public void CreateProduct(ProductBindingModel Model)
{
try
{
_productLogic.Create(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания блюда");
throw;
}
}
[HttpPost]
public void UpdateProduct(ProductBindingModel Model)
{
try
{
_productLogic.Update(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления блюда");
throw;
}
}
[HttpDelete]
public void DeleteProduct(ProductBindingModel Model)
{
try
{
_productLogic.Delete(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления блюда");
throw;
}
}
}
}

View File

@ -0,0 +1,69 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
using DiningRoomDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace DiningRoomRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class UserController : Controller
{
private readonly ILogger _logger;
private readonly IUserLogic _logic;
public UserController(IUserLogic logic, ILogger<UserController> logger)
{
_logic = logic;
_logger = logger;
}
[HttpGet]
public UserViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Login = login,
Password = password,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(UserBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(UserBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj" />
<ProjectReference Include="..\DiningRoomContracts\DiningRoomContracts.csproj" />
<ProjectReference Include="..\DiningRoomDatabaseImplement\DiningRoomDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,50 @@
using DiningRoomBusinessLogic.BusinessLogics;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.StorageContracts;
using DiningRoomDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
var Builder = WebApplication.CreateBuilder(args);
Builder.Services.AddTransient<IUserStorage, UserStorage>();
Builder.Services.AddTransient<ICardStorage, CardStorage>();
Builder.Services.AddTransient<IDrinkStorage, DrinkStorage>();
Builder.Services.AddTransient<IOrderStorage, OrderStorage>();
Builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
Builder.Services.AddTransient<IProductStorage, ProductStorage>();
Builder.Services.AddTransient<IUserLogic, UserLogic>();
Builder.Services.AddTransient<ICardLogic, CardLogic>();
Builder.Services.AddTransient<IDrinkLogic, DrinkLogic>();
Builder.Services.AddTransient<IOrderLogic, OrderLogic>();
Builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
Builder.Services.AddTransient<IProductLogic, ProductLogic>();
Builder.Services.AddTransient<IReportLogic, ReportLogic>();
Builder.Services.AddControllers();
Builder.Services.AddEndpointsApiExplorer();
Builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "DiningRoomRestApi",
Version = "v1"
});
});
var App = Builder.Build();
if (App.Environment.IsDevelopment())
{
App.UseSwagger();
App.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DiningRoomRestApi v1"));
}
App.UseHttpsRedirection();
App.UseAuthorization();
App.MapControllers();
App.Run();

View File

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38485",
"sslPort": 44318
}
},
"profiles": {
"DiningRoomRestApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7080;http://localhost:5150",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}