From 82c4b03ddf67116690e599b0b5799f409c8bb196 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Mon, 29 Apr 2024 13:59:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D1=83=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?,=20=D1=81=D0=B2=D0=B0=D0=B3=D0=B5=D1=80=20=D0=BE=D0=B6=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/CardLogic.cs | 2 +- .../BusinessLogic/ClientLogic.cs | 2 +- .../BusinessLogic/OperationLogic.cs | 2 +- .../BusinessLogic/RequestLogic.cs | 2 +- Bank/BankDatabaseImplement/BankDatabase.cs | 8 ++-- ... 20240429095730_InitialCreate.Designer.cs} | 15 +++--- ...ate.cs => 20240429095730_InitialCreate.cs} | 13 +++--- .../Migrations/BankDatabaseModelSnapshot.cs | 13 ++---- Bank/BankDatabaseImplement/Models/Account.cs | 5 +- Bank/BankDatabaseImplement/Models/Card.cs | 6 +-- Bank/BankRestApi/BankRestApi.csproj | 1 + .../BankRestApi/Controllers/MainController.cs | 2 +- Bank/BankRestApi/Program.cs | 46 +++++++++++++++---- Bank/BankRestApi/log4net.config | 16 +++++++ 14 files changed, 86 insertions(+), 47 deletions(-) rename Bank/BankDatabaseImplement/Migrations/{20240429090634_InitialCreate.Designer.cs => 20240429095730_InitialCreate.Designer.cs} (97%) rename Bank/BankDatabaseImplement/Migrations/{20240429090634_InitialCreate.cs => 20240429095730_InitialCreate.cs} (97%) create mode 100644 Bank/BankRestApi/log4net.config diff --git a/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs index 480a025..95c368e 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs @@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly ICardStorage _cardStorage; - public CardLogic(ILogger logger, ICardStorage cardStorage) + public CardLogic(ILogger logger, ICardStorage cardStorage) { _logger = logger; _cardStorage = cardStorage; diff --git a/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs index 6203e4f..e354552 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs @@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IClientStorage _clientStorage; - public ClientLogic(ILogger logger, IClientStorage clientStorage) + public ClientLogic(ILogger logger, IClientStorage clientStorage) { _logger = logger; _clientStorage = clientStorage; diff --git a/Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs index 42e46d9..9e51658 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs @@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOperationStorage _operationStorage; - public OperationLogic(ILogger logger, IOperationStorage operationStorage) + public OperationLogic(ILogger logger, IOperationStorage operationStorage) { _logger = logger; _operationStorage = operationStorage; diff --git a/Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs index 224edb7..8aa75cc 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs @@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IRequestStorage _requestStorage; - public RequestLogic(ILogger logger, IRequestStorage requestStorage) + public RequestLogic(ILogger logger, IRequestStorage requestStorage) { _logger = logger; _requestStorage = requestStorage; diff --git a/Bank/BankDatabaseImplement/BankDatabase.cs b/Bank/BankDatabaseImplement/BankDatabase.cs index 099503d..14124a2 100644 --- a/Bank/BankDatabaseImplement/BankDatabase.cs +++ b/Bank/BankDatabaseImplement/BankDatabase.cs @@ -20,19 +20,19 @@ namespace BankDatabaseImplement modelBuilder.Entity() .HasOne(t => t.SenderAccount) .WithMany(a => a.SenderTransfers) - .HasForeignKey(t => t.SenderAccountId); + .HasForeignKey(t => t.SenderAccountId).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity() .HasOne(t => t.RecipientAccount) .WithMany(a => a.RecipientTransfers) - .HasForeignKey(t => t.RecipientAccountId); + .HasForeignKey(t => t.RecipientAccountId).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity() .HasOne(t => t.SenderCard) .WithMany(a => a.SenderOperations) - .HasForeignKey(t => t.SenderCardId); + .HasForeignKey(t => t.SenderCardId).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity() .HasOne(t => t.RecipientCard) .WithMany(a => a.RecipientOperations) - .HasForeignKey(t => t.RecipientCardId); + .HasForeignKey(t => t.RecipientCardId).OnDelete(DeleteBehavior.Restrict); base.OnModelCreating(modelBuilder); } diff --git a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs b/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs similarity index 97% rename from Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs rename to Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs index edc8afa..05ecd1a 100644 --- a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs +++ b/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BankDatabaseImplement.Migrations { [DbContext(typeof(BankDatabase))] - [Migration("20240429090634_InitialCreate")] + [Migration("20240429095730_InitialCreate")] partial class InitialCreate { /// @@ -88,7 +88,6 @@ namespace BankDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("AccountId") - .IsRequired() .HasColumnType("int"); b.Property("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"); diff --git a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs b/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs similarity index 97% rename from Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs rename to Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs index f9799b6..dd7c592 100644 --- a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs +++ b/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs @@ -110,7 +110,7 @@ namespace BankDatabaseImplement.Migrations ReleaseDate = table.Column(type: "datetime2", nullable: false), ExpirationDate = table.Column(type: "datetime2", nullable: false), ClientId = table.Column(type: "int", nullable: false), - AccountId = table.Column(type: "int", nullable: false) + AccountId = table.Column(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, diff --git a/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs b/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs index 15dea06..ba56066 100644 --- a/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs +++ b/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs @@ -85,7 +85,6 @@ namespace BankDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("AccountId") - .IsRequired() .HasColumnType("int"); b.Property("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"); diff --git a/Bank/BankDatabaseImplement/Models/Account.cs b/Bank/BankDatabaseImplement/Models/Account.cs index 5db3455..e856a91 100644 --- a/Bank/BankDatabaseImplement/Models/Account.cs +++ b/Bank/BankDatabaseImplement/Models/Account.cs @@ -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 AccountWithdrawals { get; set; } = new(); - [ForeignKey("SenderAccountId")] + [ForeignKey("SenderAccountId"), DeleteBehavior(DeleteBehavior.Restrict)] public virtual List SenderTransfers { get; set; } = new(); - [ForeignKey("RecipientAccountId")] + [ForeignKey("RecipientAccountId"), DeleteBehavior(DeleteBehavior.Restrict)] public virtual List RecipientTransfers { get; set; } = new(); public static Account? Create(AccountBindingModel model) diff --git a/Bank/BankDatabaseImplement/Models/Card.cs b/Bank/BankDatabaseImplement/Models/Card.cs index d192feb..1c600ee 100644 --- a/Bank/BankDatabaseImplement/Models/Card.cs +++ b/Bank/BankDatabaseImplement/Models/Card.cs @@ -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 CardRequests { get; set; } = new(); - [ForeignKey("SenderCardId")] + [ForeignKey("SenderCardId"), DeleteBehavior(DeleteBehavior.Restrict)] public virtual List SenderOperations { get; set; } = new(); - [ForeignKey("RecipientCardId")] + [ForeignKey("RecipientCardId"), DeleteBehavior(DeleteBehavior.Restrict)] public virtual List RecipientOperations { get; set; } = new(); public static Card? Create(CardBindingModel model) diff --git a/Bank/BankRestApi/BankRestApi.csproj b/Bank/BankRestApi/BankRestApi.csproj index 8dd10e9..de5c752 100644 --- a/Bank/BankRestApi/BankRestApi.csproj +++ b/Bank/BankRestApi/BankRestApi.csproj @@ -12,6 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Bank/BankRestApi/Controllers/MainController.cs b/Bank/BankRestApi/Controllers/MainController.cs index f2ee0e7..63da118 100644 --- a/Bank/BankRestApi/Controllers/MainController.cs +++ b/Bank/BankRestApi/Controllers/MainController.cs @@ -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 logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request) { _logger = logger; _client = client; diff --git a/Bank/BankRestApi/Program.cs b/Bank/BankRestApi/Program.cs index d7a851e..ba29e26 100644 --- a/Bank/BankRestApi/Program.cs +++ b/Bank/BankRestApi/Program.cs @@ -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(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +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(); \ No newline at end of file diff --git a/Bank/BankRestApi/log4net.config b/Bank/BankRestApi/log4net.config new file mode 100644 index 0000000..0a206f5 --- /dev/null +++ b/Bank/BankRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file