This commit is contained in:
dasha 2023-05-15 18:24:46 +04:00
parent a6aa2d3e35
commit b0ea2fb11e
8 changed files with 218 additions and 0 deletions

View File

@ -0,0 +1,69 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.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)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public UserViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Email = 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,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
<ProjectReference Include="..\HardwareShopClientApp\HardwareShopStorekeeperApp.csproj" />
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
<ProjectReference Include="..\HardwareShopDataModels\HardwareShopDataModels.csproj" />
<ProjectReference Include="..\HardwareShopWorkerApp\HardwareShopWorkerApp.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,56 @@
using HardwareShopBusinessLogic.BusinessLogics;
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
using HardwareShopContracts.BuisnessLogicsContracts;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.StoragesContracts;
using HardwareShopDatabaseImplement.Implements;
using HardwareShopDatabaseImplement.Implements.Storekeeper;
using HardwareShopDatabaseImplement.Implements.Worker;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IBuildStorage, BuildStorage>();
builder.Services.AddTransient<ICommentStorage, CommentStorage>();
builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
builder.Services.AddTransient<IGoodStorage, GoodStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IBuildLogic, BuildLogic>();
builder.Services.AddTransient<ICommentLogic, CommentLogic>();
builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
builder.Services.AddTransient<IGoodLogic, GoodLogic>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "SushiBarRestApi", Version = "v1" });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
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:55766",
"sslPort": 44384
}
},
"profiles": {
"HardwareShopRestApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7254;http://localhost:5254",
"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": "*"
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="d:/temp/HardwareShopRestApi.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>

View File

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopStorekeeperApp"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopWorkerApp", "HardwareShopWorkerApp\HardwareShopWorkerApp.csproj", "{3C590713-871F-4D9B-A97A-3898D4E09506}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopRestApi", "HardwareShopRestApi\HardwareShopRestApi.csproj", "{99D5A2C6-AF0C-41BE-8E41-96FF04FCF3A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -45,6 +47,10 @@ Global
{3C590713-871F-4D9B-A97A-3898D4E09506}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C590713-871F-4D9B-A97A-3898D4E09506}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C590713-871F-4D9B-A97A-3898D4E09506}.Release|Any CPU.Build.0 = Release|Any CPU
{99D5A2C6-AF0C-41BE-8E41-96FF04FCF3A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99D5A2C6-AF0C-41BE-8E41-96FF04FCF3A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99D5A2C6-AF0C-41BE-8E41-96FF04FCF3A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99D5A2C6-AF0C-41BE-8E41-96FF04FCF3A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE