Создал проект с рест
This commit is contained in:
parent
9512a118d0
commit
ee8b4dda04
@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankContracts", "BankContra
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankDatabaseImplement", "BankDatabaseImplement\BankDatabaseImplement.csproj", "{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankBusinessLogic", "BankBusinessLogic\BankBusinessLogic.csproj", "{0C433C84-5E7C-4CB9-9072-E9B2F479FBF3}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankBusinessLogic", "BankBusinessLogic\BankBusinessLogic.csproj", "{0C433C84-5E7C-4CB9-9072-E9B2F479FBF3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankRestApi", "BankRestApi\BankRestApi.csproj", "{98FCB29C-6573-4FB9-A6DE-42C90387F1C7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{0C433C84-5E7C-4CB9-9072-E9B2F479FBF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C433C84-5E7C-4CB9-9072-E9B2F479FBF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C433C84-5E7C-4CB9-9072-E9B2F479FBF3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{98FCB29C-6573-4FB9-A6DE-42C90387F1C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98FCB29C-6573-4FB9-A6DE-42C90387F1C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98FCB29C-6573-4FB9-A6DE-42C90387F1C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98FCB29C-6573-4FB9-A6DE-42C90387F1C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
20
Bank/BankRestApi/BankRestApi.csproj
Normal file
20
Bank/BankRestApi/BankRestApi.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="7.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BankBusinessLogic\BankBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||
<ProjectReference Include="..\BankDatabaseImplement\BankDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
250
Bank/BankRestApi/Controllers/MainController.cs
Normal file
250
Bank/BankRestApi/Controllers/MainController.cs
Normal file
@ -0,0 +1,250 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace BankRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _client;
|
||||
private readonly ICardLogic _card;
|
||||
private readonly IOperationLogic _operation;
|
||||
private readonly IRequestLogic _request;
|
||||
|
||||
public MainController(ILogger logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
|
||||
{
|
||||
_logger = logger;
|
||||
_client = client;
|
||||
_card = card;
|
||||
_operation = operation;
|
||||
_request = request;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ClientViewModel>? GetClientList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _client.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка клиентов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public ClientViewModel? GetClient(int ClientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _client.ReadElement(new ClientSearchModel
|
||||
{
|
||||
Id = ClientId
|
||||
});
|
||||
}catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения клиента по Id={Id}", ClientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<CardViewModel>? GetCardList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _card.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка карт");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public CardViewModel? GetCard(int CardId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _card.ReadElement(new CardSearchModel
|
||||
{
|
||||
Id = CardId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения карты по Id={Id}", CardId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OperationViewModel>? getOperationList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _operation.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка операций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public OperationViewModel? GetOperation(int OperationId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _operation.ReadElement(new OperationSearchModel
|
||||
{
|
||||
Id = OperationId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения операции по Id={Id}", OperationId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<RequestViewModel>? GetRequestList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _request.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка запросов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public RequestViewModel? GetRequest(int RequestId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _request.ReadElement(new RequestSearchModel
|
||||
{
|
||||
Id = RequestId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения запроса по Id={Id}", RequestId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateClient(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_client.Create(model);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateCard(CardBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_card.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания карты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateOperation(OperationBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_operation.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания операции");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_request.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания запроса");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
public void UpdateClient(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_client.Update(model);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
public void UpdateCard(CardBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_card.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления карты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
public void UpdateOperation(OperationBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_operation.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления операции");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
public void UpdateRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_request.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления запроса");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
Bank/BankRestApi/Program.cs
Normal file
25
Bank/BankRestApi/Program.cs
Normal file
@ -0,0 +1,25 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
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();
|
31
Bank/BankRestApi/Properties/launchSettings.json
Normal file
31
Bank/BankRestApi/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:27552",
|
||||
"sslPort": 44383
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"BankRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7177;http://localhost:5116",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
Bank/BankRestApi/appsettings.Development.json
Normal file
8
Bank/BankRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
Bank/BankRestApi/appsettings.json
Normal file
9
Bank/BankRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Reference in New Issue
Block a user