Compare commits

..

No commits in common. "568700a1ae83380fb9d90ede9d91a7060b7d8832" and "6b405f61c6b84497d9d59fc2f6cbe5ae7e0a2fb6" have entirely different histories.

14 changed files with 47 additions and 86 deletions

View File

@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly ICardStorage _cardStorage;
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage)
public CardLogic(ILogger logger, ICardStorage cardStorage)
{
_logger = logger;
_cardStorage = cardStorage;

View File

@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
public ClientLogic(ILogger logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;

View File

@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IOperationStorage _operationStorage;
public OperationLogic(ILogger<OperationLogic> logger, IOperationStorage operationStorage)
public OperationLogic(ILogger logger, IOperationStorage operationStorage)
{
_logger = logger;
_operationStorage = operationStorage;

View File

@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IRequestStorage _requestStorage;
public RequestLogic(ILogger<RequestLogic> logger, IRequestStorage requestStorage)
public RequestLogic(ILogger logger, IRequestStorage requestStorage)
{
_logger = logger;
_requestStorage = requestStorage;

View File

@ -20,19 +20,19 @@ namespace BankDatabaseImplement
modelBuilder.Entity<Transfer>()
.HasOne(t => t.SenderAccount)
.WithMany(a => a.SenderTransfers)
.HasForeignKey(t => t.SenderAccountId).OnDelete(DeleteBehavior.Restrict);
.HasForeignKey(t => t.SenderAccountId);
modelBuilder.Entity<Transfer>()
.HasOne(t => t.RecipientAccount)
.WithMany(a => a.RecipientTransfers)
.HasForeignKey(t => t.RecipientAccountId).OnDelete(DeleteBehavior.Restrict);
.HasForeignKey(t => t.RecipientAccountId);
modelBuilder.Entity<Operation>()
.HasOne(t => t.SenderCard)
.WithMany(a => a.SenderOperations)
.HasForeignKey(t => t.SenderCardId).OnDelete(DeleteBehavior.Restrict);
.HasForeignKey(t => t.SenderCardId);
modelBuilder.Entity<Operation>()
.HasOne(t => t.RecipientCard)
.WithMany(a => a.RecipientOperations)
.HasForeignKey(t => t.RecipientCardId).OnDelete(DeleteBehavior.Restrict);
.HasForeignKey(t => t.RecipientCardId);
base.OnModelCreating(modelBuilder);
}

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BankDatabaseImplement.Migrations
{
[DbContext(typeof(BankDatabase))]
[Migration("20240429095730_InitialCreate")]
[Migration("20240429090634_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -88,6 +88,7 @@ namespace BankDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("AccountId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("ClientId")
@ -339,7 +340,9 @@ namespace BankDatabaseImplement.Migrations
{
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
.WithMany()
.HasForeignKey("AccountId");
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Cards")
@ -376,13 +379,13 @@ namespace BankDatabaseImplement.Migrations
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
.WithMany("RecipientOperations")
.HasForeignKey("RecipientCardId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
.WithMany("SenderOperations")
.HasForeignKey("SenderCardId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("RecipientCard");
@ -401,13 +404,13 @@ namespace BankDatabaseImplement.Migrations
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
.WithMany("RecipientTransfers")
.HasForeignKey("RecipientAccountId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
.WithMany("SenderTransfers")
.HasForeignKey("SenderAccountId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Operation");

View File

@ -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: true)
AccountId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
@ -119,7 +119,8 @@ namespace BankDatabaseImplement.Migrations
name: "FK_Cards_Accounts_AccountId",
column: x => x.AccountId,
principalTable: "Accounts",
principalColumn: "Id");
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Cards_Clients_ClientId",
column: x => x.ClientId,
@ -201,13 +202,13 @@ namespace BankDatabaseImplement.Migrations
column: x => x.RecipientCardId,
principalTable: "Cards",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Operations_Cards_SenderCardId",
column: x => x.SenderCardId,
principalTable: "Cards",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -230,13 +231,13 @@ namespace BankDatabaseImplement.Migrations
column: x => x.RecipientAccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Transfers_Accounts_SenderAccountId",
column: x => x.SenderAccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Transfers_Operations_OperationId",
column: x => x.OperationId,

View File

@ -85,6 +85,7 @@ namespace BankDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("AccountId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("ClientId")
@ -336,7 +337,9 @@ namespace BankDatabaseImplement.Migrations
{
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
.WithMany()
.HasForeignKey("AccountId");
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Cards")
@ -373,13 +376,13 @@ namespace BankDatabaseImplement.Migrations
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
.WithMany("RecipientOperations")
.HasForeignKey("RecipientCardId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
.WithMany("SenderOperations")
.HasForeignKey("SenderCardId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("RecipientCard");
@ -398,13 +401,13 @@ namespace BankDatabaseImplement.Migrations
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
.WithMany("RecipientTransfers")
.HasForeignKey("RecipientAccountId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
.WithMany("SenderTransfers")
.HasForeignKey("SenderAccountId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Operation");

View File

@ -1,7 +1,6 @@
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using BankDataModels.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
@ -28,9 +27,9 @@ namespace BankDatabaseImplement.Models
public virtual Manager? Manager { get; private set; }
[ForeignKey("AccountId")]
public virtual List<AccountWithdrawal> AccountWithdrawals { get; set; } = new();
[ForeignKey("SenderAccountId"), DeleteBehavior(DeleteBehavior.Restrict)]
[ForeignKey("SenderAccountId")]
public virtual List<Transfer> SenderTransfers { get; set; } = new();
[ForeignKey("RecipientAccountId"), DeleteBehavior(DeleteBehavior.Restrict)]
[ForeignKey("RecipientAccountId")]
public virtual List<Transfer> RecipientTransfers { get; set; } = new();
public static Account? Create(AccountBindingModel model)

View File

@ -1,7 +1,6 @@
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using BankDataModels.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -29,13 +28,14 @@ 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"), DeleteBehavior(DeleteBehavior.Restrict)]
[ForeignKey("SenderCardId")]
public virtual List<Operation> SenderOperations { get; set; } = new();
[ForeignKey("RecipientCardId"), DeleteBehavior(DeleteBehavior.Restrict)]
[ForeignKey("RecipientCardId")]
public virtual List<Operation> RecipientOperations { get; set; } = new();
public static Card? Create(CardBindingModel model)

View File

@ -12,7 +12,6 @@
<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>

View File

@ -18,7 +18,7 @@ namespace BankRestApi.Controllers
private readonly IOperationLogic _operation;
private readonly IRequestLogic _request;
public MainController(ILogger<MainController> logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
public MainController(ILogger logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
{
_logger = logger;
_client = client;

View File

@ -1,53 +1,25 @@
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
// 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"
});
});
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
"BankRestApi v1"));
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
app.Run();

View File

@ -1,16 +0,0 @@
<?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>