Допилил базу данных, свагер ожил
This commit is contained in:
parent
3eebc8e4f8
commit
82c4b03ddf
@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICardStorage _cardStorage;
|
||||
public CardLogic(ILogger logger, ICardStorage cardStorage)
|
||||
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_cardStorage = cardStorage;
|
||||
|
@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public ClientLogic(ILogger logger, IClientStorage clientStorage)
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
|
@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOperationStorage _operationStorage;
|
||||
public OperationLogic(ILogger logger, IOperationStorage operationStorage)
|
||||
public OperationLogic(ILogger<OperationLogic> logger, IOperationStorage operationStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_operationStorage = operationStorage;
|
||||
|
@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
public RequestLogic(ILogger logger, IRequestStorage requestStorage)
|
||||
public RequestLogic(ILogger<RequestLogic> logger, IRequestStorage requestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestStorage = requestStorage;
|
||||
|
@ -20,19 +20,19 @@ namespace BankDatabaseImplement
|
||||
modelBuilder.Entity<Transfer>()
|
||||
.HasOne(t => t.SenderAccount)
|
||||
.WithMany(a => a.SenderTransfers)
|
||||
.HasForeignKey(t => t.SenderAccountId);
|
||||
.HasForeignKey(t => t.SenderAccountId).OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Transfer>()
|
||||
.HasOne(t => t.RecipientAccount)
|
||||
.WithMany(a => a.RecipientTransfers)
|
||||
.HasForeignKey(t => t.RecipientAccountId);
|
||||
.HasForeignKey(t => t.RecipientAccountId).OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Operation>()
|
||||
.HasOne(t => t.SenderCard)
|
||||
.WithMany(a => a.SenderOperations)
|
||||
.HasForeignKey(t => t.SenderCardId);
|
||||
.HasForeignKey(t => t.SenderCardId).OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Operation>()
|
||||
.HasOne(t => t.RecipientCard)
|
||||
.WithMany(a => a.RecipientOperations)
|
||||
.HasForeignKey(t => t.RecipientCardId);
|
||||
.HasForeignKey(t => t.RecipientCardId).OnDelete(DeleteBehavior.Restrict);
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace BankDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BankDatabase))]
|
||||
[Migration("20240429090634_InitialCreate")]
|
||||
[Migration("20240429095730_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -88,7 +88,6 @@ namespace BankDatabaseImplement.Migrations
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("AccountId")
|
||||
.IsRequired()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
@ -340,9 +339,7 @@ namespace BankDatabaseImplement.Migrations
|
||||
{
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
|
||||
.WithMany()
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
.HasForeignKey("AccountId");
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Cards")
|
||||
@ -379,13 +376,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
|
||||
.WithMany("RecipientOperations")
|
||||
.HasForeignKey("RecipientCardId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
|
||||
.WithMany("SenderOperations")
|
||||
.HasForeignKey("SenderCardId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("RecipientCard");
|
||||
@ -404,13 +401,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
|
||||
.WithMany("RecipientTransfers")
|
||||
.HasForeignKey("RecipientAccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
|
||||
.WithMany("SenderTransfers")
|
||||
.HasForeignKey("SenderAccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Operation");
|
@ -110,7 +110,7 @@ namespace BankDatabaseImplement.Migrations
|
||||
ReleaseDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
AccountId = table.Column<int>(type: "int", nullable: false)
|
||||
AccountId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -119,8 +119,7 @@ namespace BankDatabaseImplement.Migrations
|
||||
name: "FK_Cards_Accounts_AccountId",
|
||||
column: x => x.AccountId,
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Cards_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
@ -202,13 +201,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
column: x => x.RecipientCardId,
|
||||
principalTable: "Cards",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Operations_Cards_SenderCardId",
|
||||
column: x => x.SenderCardId,
|
||||
principalTable: "Cards",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@ -231,13 +230,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
column: x => x.RecipientAccountId,
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Transfers_Accounts_SenderAccountId",
|
||||
column: x => x.SenderAccountId,
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Transfers_Operations_OperationId",
|
||||
column: x => x.OperationId,
|
@ -85,7 +85,6 @@ namespace BankDatabaseImplement.Migrations
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("AccountId")
|
||||
.IsRequired()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
@ -337,9 +336,7 @@ namespace BankDatabaseImplement.Migrations
|
||||
{
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
|
||||
.WithMany()
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
.HasForeignKey("AccountId");
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Cards")
|
||||
@ -376,13 +373,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
|
||||
.WithMany("RecipientOperations")
|
||||
.HasForeignKey("RecipientCardId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
|
||||
.WithMany("SenderOperations")
|
||||
.HasForeignKey("SenderCardId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("RecipientCard");
|
||||
@ -401,13 +398,13 @@ namespace BankDatabaseImplement.Migrations
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
|
||||
.WithMany("RecipientTransfers")
|
||||
.HasForeignKey("RecipientAccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
|
||||
.WithMany("SenderTransfers")
|
||||
.HasForeignKey("SenderAccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Operation");
|
||||
|
@ -1,6 +1,7 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Identity.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -27,9 +28,9 @@ namespace BankDatabaseImplement.Models
|
||||
public virtual Manager? Manager { get; private set; }
|
||||
[ForeignKey("AccountId")]
|
||||
public virtual List<AccountWithdrawal> AccountWithdrawals { get; set; } = new();
|
||||
[ForeignKey("SenderAccountId")]
|
||||
[ForeignKey("SenderAccountId"), DeleteBehavior(DeleteBehavior.Restrict)]
|
||||
public virtual List<Transfer> SenderTransfers { get; set; } = new();
|
||||
[ForeignKey("RecipientAccountId")]
|
||||
[ForeignKey("RecipientAccountId"), DeleteBehavior(DeleteBehavior.Restrict)]
|
||||
public virtual List<Transfer> RecipientTransfers { get; set; } = new();
|
||||
|
||||
public static Account? Create(AccountBindingModel model)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
@ -28,14 +29,13 @@ namespace BankDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
public virtual Client? Client { get; private set; }
|
||||
[Required]
|
||||
public int? AccountId { get; set; } = null;
|
||||
public virtual Account? Account { get; private set; }
|
||||
[ForeignKey("CardId")]
|
||||
public virtual List<CardRequest> CardRequests { get; set; } = new();
|
||||
[ForeignKey("SenderCardId")]
|
||||
[ForeignKey("SenderCardId"), DeleteBehavior(DeleteBehavior.Restrict)]
|
||||
public virtual List<Operation> SenderOperations { get; set; } = new();
|
||||
[ForeignKey("RecipientCardId")]
|
||||
[ForeignKey("RecipientCardId"), DeleteBehavior(DeleteBehavior.Restrict)]
|
||||
public virtual List<Operation> RecipientOperations { get; set; } = new();
|
||||
|
||||
public static Card? Create(CardBindingModel model)
|
||||
|
@ -12,6 +12,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.9" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace BankRestApi.Controllers
|
||||
private readonly IOperationLogic _operation;
|
||||
private readonly IRequestLogic _request;
|
||||
|
||||
public MainController(ILogger logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
|
||||
public MainController(ILogger<MainController> logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
|
||||
{
|
||||
_logger = logger;
|
||||
_client = client;
|
||||
|
@ -1,25 +1,53 @@
|
||||
using BankBusinessLogic.BusinessLogic;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankDatabaseImplement.Implements;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
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<ICardStorage, CardStorage>();
|
||||
builder.Services.AddTransient<IOperationStorage, OperationStorage>();
|
||||
builder.Services.AddTransient<IRequestStorage, RequestStorage>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<ICardLogic, CardLogic>();
|
||||
builder.Services.AddTransient<IOperationLogic, OperationLogic>();
|
||||
builder.Services.AddTransient<IRequestLogic, RequestLogic>();
|
||||
builder.Services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// 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 = "BankRestApi",
|
||||
Version
|
||||
= "v1"
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
|
||||
"BankRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
16
Bank/BankRestApi/log4net.config
Normal file
16
Bank/BankRestApi/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/BankRestApi.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