РЕСТ АПИ
This commit is contained in:
parent
752d9b58ef
commit
93c62edf00
@ -13,9 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "Law
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmDatabaseImplement", "LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj", "{CB0444D3-5BDA-42DB-95F9-60191AE9073A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmDatabaseImplement", "LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj", "{CB0444D3-5BDA-42DB-95F9-60191AE9073A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmRestApi", "LawFirmRestApi\LawFirmRestApi.csproj", "{8DB8A004-DB42-46F2-8EAA-AAEB498FCD36}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -51,6 +53,10 @@ Global
|
||||
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8DB8A004-DB42-46F2-8EAA-AAEB498FCD36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8DB8A004-DB42-46F2-8EAA-AAEB498FCD36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8DB8A004-DB42-46F2-8EAA-AAEB498FCD36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8DB8A004-DB42-46F2-8EAA-AAEB498FCD36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
64
LawFirm/LawFirmRestApi/Controllers/ClientController.cs
Normal file
64
LawFirm/LawFirmRestApi/Controllers/ClientController.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LawFirmRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
[HttpGet]
|
||||
public ClientViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ClientSearchModel
|
||||
{
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateData(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
LawFirm/LawFirmRestApi/Controllers/MainController.cs
Normal file
84
LawFirm/LawFirmRestApi/Controllers/MainController.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LawFirmRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly IDocumentLogic _document;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, IDocumentLogic document)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_document = document;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<DocumentViewModel>? GetDocumentList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _document.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка документов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public DocumentViewModel? GetDocument(int documentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _document.ReadElement(new DocumentSearchModel
|
||||
{
|
||||
Id = documentId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения документа по id={Id}", documentId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetOrders(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.CreateOrder(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
LawFirm/LawFirmRestApi/LawFirmRestApi.csproj
Normal file
20
LawFirm/LawFirmRestApi/LawFirmRestApi.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<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="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||
<ProjectReference Include="..\LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
46
LawFirm/LawFirmRestApi/Program.cs
Normal file
46
LawFirm/LawFirmRestApi/Program.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using LawFirmBusinessLogic.BusinessLogics;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmDatabaseImplement.Implements;
|
||||
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<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IDocumentStorage, DocumentStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IDocumentLogic, DocumentLogic>();
|
||||
|
||||
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 = "LawFirmRestApi",
|
||||
Version = "v1"
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "LawFirmRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
31
LawFirm/LawFirmRestApi/Properties/launchSettings.json
Normal file
31
LawFirm/LawFirmRestApi/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:10641",
|
||||
"sslPort": 44398
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"LawFirmRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7163;http://localhost:5137",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
LawFirm/LawFirmRestApi/appsettings.Development.json
Normal file
8
LawFirm/LawFirmRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
LawFirm/LawFirmRestApi/appsettings.json
Normal file
9
LawFirm/LawFirmRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
16
LawFirm/LawFirmRestApi/log4net.config
Normal file
16
LawFirm/LawFirmRestApi/log4net.config
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<log4net>
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="c:/temp/LawFirmRestApi.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>
|
Loading…
Reference in New Issue
Block a user