Merge pull request 'Task_5_Api' (#7) from Task_5_Api into main
Reviewed-on: #7 feat: реализация web api, которая скорее всего работает, но чиниться будет уже в следующих тасках
This commit was merged in pull request #7.
This commit is contained in:
@@ -14,4 +14,9 @@
|
|||||||
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="BankWebApi" />
|
||||||
|
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ internal class CurrencyBusinessLogicContract(
|
|||||||
|
|
||||||
private readonly ILogger _logger = logger;
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
public List<CurrencyDataModel> GetAllCurrencys()
|
public List<CurrencyDataModel> GetAllCurrencies()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("get all currencys programs");
|
_logger.LogInformation("get all currencys programs");
|
||||||
return _currencyStorageContract.GetList();
|
return _currencyStorageContract.GetList();
|
||||||
|
|||||||
@@ -27,24 +27,19 @@ internal class PeriodBusinessLogicContract(
|
|||||||
_logger.LogInformation("get all periods");
|
_logger.LogInformation("get all periods");
|
||||||
return _periodStorageContract.GetList();
|
return _periodStorageContract.GetList();
|
||||||
}
|
}
|
||||||
|
public List<PeriodDataModel> GetAllPeriodsByStartTime(DateTime fromDate)
|
||||||
public List<PeriodDataModel> GetAllPeriodsByEndTime(DateTime fromDate, DateTime toDate)
|
|
||||||
{
|
{
|
||||||
if (toDate.IsDateNotOlder(toDate))
|
if (fromDate.IsDateNotOlder(DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
throw new IncorrectDatesException(fromDate, toDate);
|
throw new IncorrectDatesException(fromDate, DateTime.UtcNow);
|
||||||
}
|
}
|
||||||
return _periodStorageContract.GetList(fromDate, toDate).OrderBy(x => x.EndTime).ToList()
|
return _periodStorageContract.GetList(startDate: fromDate).OrderBy(x => x.StartTime).ToList()
|
||||||
?? throw new NullListException(nameof(PeriodDataModel));
|
?? throw new NullListException(nameof(PeriodDataModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PeriodDataModel> GetAllPeriodsByStartTime(DateTime fromDate, DateTime toDate)
|
public List<PeriodDataModel> GetAllPeriodsByEndTime(DateTime toDate)
|
||||||
{
|
{
|
||||||
if (toDate.IsDateNotOlder(toDate))
|
return _periodStorageContract.GetList(endDate: toDate).OrderBy(x => x.EndTime).ToList()
|
||||||
{
|
|
||||||
throw new IncorrectDatesException(fromDate, toDate);
|
|
||||||
}
|
|
||||||
return _periodStorageContract.GetList(fromDate, toDate).OrderBy(x => x.StartTime).ToList()
|
|
||||||
?? throw new NullListException(nameof(PeriodDataModel));
|
?? throw new NullListException(nameof(PeriodDataModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
TheBank/BankContracts/AdapterContracts/IClerkAdapter.cs
Normal file
18
TheBank/BankContracts/AdapterContracts/IClerkAdapter.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// контракт адаптера для клерка
|
||||||
|
/// </summary>
|
||||||
|
public interface IClerkAdapter
|
||||||
|
{
|
||||||
|
ClerkOperationResponse GetList();
|
||||||
|
|
||||||
|
ClerkOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
ClerkOperationResponse RegisterClerk(ClerkBindingModel clerkModel);
|
||||||
|
|
||||||
|
ClerkOperationResponse ChangeClerkInfo(ClerkBindingModel clerkModel);
|
||||||
|
}
|
||||||
25
TheBank/BankContracts/AdapterContracts/IClientAdapter.cs
Normal file
25
TheBank/BankContracts/AdapterContracts/IClientAdapter.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// контракт адаптера для клиента
|
||||||
|
/// </summary>
|
||||||
|
public interface IClientAdapter
|
||||||
|
{
|
||||||
|
ClientOperationResponse GetList();
|
||||||
|
|
||||||
|
ClientOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
ClientOperationResponse GetListByClerk(string clerkId);
|
||||||
|
|
||||||
|
ClientOperationResponse RegisterClient(ClientBindingModel clientModel);
|
||||||
|
|
||||||
|
ClientOperationResponse ChangeClientInfo(ClientBindingModel clientModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
public interface ICreditProgramAdapter
|
||||||
|
{
|
||||||
|
CreditProgramOperationResponse GetList();
|
||||||
|
|
||||||
|
CreditProgramOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
CreditProgramOperationResponse GetListByStorekeeper(string storekeeperId);
|
||||||
|
|
||||||
|
CreditProgramOperationResponse GetListByPeriod(string periodId);
|
||||||
|
|
||||||
|
CreditProgramOperationResponse RegisterCreditProgram(CreditProgramBindingModel creditProgramModel);
|
||||||
|
|
||||||
|
CreditProgramOperationResponse ChangeCreditProgramInfo(CreditProgramBindingModel creditProgramModel);
|
||||||
|
}
|
||||||
20
TheBank/BankContracts/AdapterContracts/ICurrencyAdapter.cs
Normal file
20
TheBank/BankContracts/AdapterContracts/ICurrencyAdapter.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// контракт адаптера для валюыты
|
||||||
|
/// </summary>
|
||||||
|
public interface ICurrencyAdapter
|
||||||
|
{
|
||||||
|
CurrencyOperationResponse GetList();
|
||||||
|
|
||||||
|
CurrencyOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
CurrencyOperationResponse GetListByStorekeeper(string storekeeperId);
|
||||||
|
|
||||||
|
CurrencyOperationResponse MakeCurrency(CurrencyBindingModel currencyModel);
|
||||||
|
|
||||||
|
CurrencyOperationResponse ChangeCurrencyInfo(CurrencyBindingModel currencyModel);
|
||||||
|
}
|
||||||
20
TheBank/BankContracts/AdapterContracts/IDepositAdapter.cs
Normal file
20
TheBank/BankContracts/AdapterContracts/IDepositAdapter.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// контракт адаптера для вклада
|
||||||
|
/// </summary>
|
||||||
|
public interface IDepositAdapter
|
||||||
|
{
|
||||||
|
DepositOperationResponse GetList();
|
||||||
|
|
||||||
|
DepositOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
DepositOperationResponse GetListByClerk(string clerkId);
|
||||||
|
|
||||||
|
DepositOperationResponse MakeDeposit(DepositBindingModel depositModel);
|
||||||
|
|
||||||
|
DepositOperationResponse ChangeDepositInfo(DepositBindingModel depositModel);
|
||||||
|
}
|
||||||
21
TheBank/BankContracts/AdapterContracts/IPeriodAdapter.cs
Normal file
21
TheBank/BankContracts/AdapterContracts/IPeriodAdapter.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
public interface IPeriodAdapter
|
||||||
|
{
|
||||||
|
PeriodOperationResponse GetList();
|
||||||
|
|
||||||
|
PeriodOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
PeriodOperationResponse GetListByStorekeeper(string storekeeperId);
|
||||||
|
|
||||||
|
PeriodOperationResponse GetListByStartTime(DateTime fromDate);
|
||||||
|
|
||||||
|
PeriodOperationResponse GetListByEndTime(DateTime toDate);
|
||||||
|
|
||||||
|
PeriodOperationResponse RegisterPeriod(PeriodBindingModel periodModel);
|
||||||
|
|
||||||
|
PeriodOperationResponse ChangePeriodInfo(PeriodBindingModel periodModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
public interface IReplenishmentAdapter
|
||||||
|
{
|
||||||
|
ReplenishmentOperationResponse GetList();
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse GetListByClerk(string clerkId);
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse GetListByDeposit(string depositId);
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse GetListByDate(DateTime fromDate, DateTime toDate);
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse RegisterReplenishment(ReplenishmentBindingModel replenishmentModel);
|
||||||
|
|
||||||
|
ReplenishmentOperationResponse ChangeReplenishmentInfo(ReplenishmentBindingModel replenishmentModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// контракт адаптера для кладовщика
|
||||||
|
/// </summary>
|
||||||
|
public interface IStorekeeperAdapter
|
||||||
|
{
|
||||||
|
StorekeeperOperationResponse GetList();
|
||||||
|
|
||||||
|
StorekeeperOperationResponse GetElement(string data);
|
||||||
|
|
||||||
|
StorekeeperOperationResponse RegisterStorekeeper(StorekeeperBindingModel storekeeperModel);
|
||||||
|
|
||||||
|
StorekeeperOperationResponse ChangeStorekeeperInfo(StorekeeperBindingModel storekeeperModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class ClerkOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static ClerkOperationResponse OK(List<ClerkViewModel> data) =>
|
||||||
|
OK<ClerkOperationResponse, List<ClerkViewModel>>(data);
|
||||||
|
|
||||||
|
public static ClerkOperationResponse OK(ClerkViewModel data) =>
|
||||||
|
OK<ClerkOperationResponse, ClerkViewModel>(data);
|
||||||
|
|
||||||
|
public static ClerkOperationResponse NoContent() => NoContent<ClerkOperationResponse>();
|
||||||
|
|
||||||
|
public static ClerkOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<ClerkOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ClerkOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<ClerkOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ClerkOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<ClerkOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class ClientOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static ClientOperationResponse OK(List<ClientViewModel> data) =>
|
||||||
|
OK<ClientOperationResponse, List<ClientViewModel>>(data);
|
||||||
|
|
||||||
|
public static ClientOperationResponse OK(ClientViewModel data) =>
|
||||||
|
OK<ClientOperationResponse, ClientViewModel>(data);
|
||||||
|
|
||||||
|
public static ClientOperationResponse NoContent() => NoContent<ClientOperationResponse>();
|
||||||
|
|
||||||
|
public static ClientOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<ClientOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ClientOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<ClientOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ClientOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<ClientOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class CreditProgramOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static CreditProgramOperationResponse OK(List<CreditProgramViewModel> data) =>
|
||||||
|
OK<CreditProgramOperationResponse, List<CreditProgramViewModel>>(data);
|
||||||
|
|
||||||
|
public static CreditProgramOperationResponse OK(CreditProgramViewModel data) =>
|
||||||
|
OK<CreditProgramOperationResponse, CreditProgramViewModel>(data);
|
||||||
|
|
||||||
|
public static CreditProgramOperationResponse NoContent() => NoContent<CreditProgramOperationResponse>();
|
||||||
|
|
||||||
|
public static CreditProgramOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<CreditProgramOperationResponse>(message);
|
||||||
|
|
||||||
|
public static CreditProgramOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<CreditProgramOperationResponse>(message);
|
||||||
|
|
||||||
|
public static CreditProgramOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<CreditProgramOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class CurrencyOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static CurrencyOperationResponse OK(List<CurrencyViewModel> data) =>
|
||||||
|
OK<CurrencyOperationResponse, List<CurrencyViewModel>>(data);
|
||||||
|
|
||||||
|
public static CurrencyOperationResponse OK(CurrencyViewModel data) =>
|
||||||
|
OK<CurrencyOperationResponse, CurrencyViewModel>(data);
|
||||||
|
|
||||||
|
public static CurrencyOperationResponse NoContent() => NoContent<CurrencyOperationResponse>();
|
||||||
|
|
||||||
|
public static CurrencyOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<CurrencyOperationResponse>(message);
|
||||||
|
|
||||||
|
public static CurrencyOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<CurrencyOperationResponse>(message);
|
||||||
|
|
||||||
|
public static CurrencyOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<CurrencyOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class DepositOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static DepositOperationResponse OK(List<DepositViewModel> data) =>
|
||||||
|
OK<DepositOperationResponse, List<DepositViewModel>>(data);
|
||||||
|
|
||||||
|
public static DepositOperationResponse OK(DepositViewModel data) =>
|
||||||
|
OK<DepositOperationResponse, DepositViewModel>(data);
|
||||||
|
|
||||||
|
public static DepositOperationResponse NoContent() => NoContent<DepositOperationResponse>();
|
||||||
|
|
||||||
|
public static DepositOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<DepositOperationResponse>(message);
|
||||||
|
|
||||||
|
public static DepositOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<DepositOperationResponse>(message);
|
||||||
|
|
||||||
|
public static DepositOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<DepositOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class PeriodOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static PeriodOperationResponse OK(List<PeriodViewModel> data) =>
|
||||||
|
OK<PeriodOperationResponse, List<PeriodViewModel>>(data);
|
||||||
|
|
||||||
|
public static PeriodOperationResponse OK(PeriodViewModel data) =>
|
||||||
|
OK<PeriodOperationResponse, PeriodViewModel>(data);
|
||||||
|
|
||||||
|
public static PeriodOperationResponse NoContent() => NoContent<PeriodOperationResponse>();
|
||||||
|
|
||||||
|
public static PeriodOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<PeriodOperationResponse>(message);
|
||||||
|
|
||||||
|
public static PeriodOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<PeriodOperationResponse>(message);
|
||||||
|
|
||||||
|
public static PeriodOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<PeriodOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class ReplenishmentOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static ReplenishmentOperationResponse OK(List<ReplenishmentViewModel> data) =>
|
||||||
|
OK<ReplenishmentOperationResponse, List<ReplenishmentViewModel>>(data);
|
||||||
|
|
||||||
|
public static ReplenishmentOperationResponse OK(ReplenishmentViewModel data) =>
|
||||||
|
OK<ReplenishmentOperationResponse, ReplenishmentViewModel>(data);
|
||||||
|
|
||||||
|
public static ReplenishmentOperationResponse NoContent() => NoContent<ReplenishmentOperationResponse>();
|
||||||
|
|
||||||
|
public static ReplenishmentOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<ReplenishmentOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ReplenishmentOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<ReplenishmentOperationResponse>(message);
|
||||||
|
|
||||||
|
public static ReplenishmentOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<ReplenishmentOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
|
||||||
|
public class StorekeeperOperationResponse : OperationResponse
|
||||||
|
{
|
||||||
|
public static StorekeeperOperationResponse OK(List<StorekeeperViewModel> data) =>
|
||||||
|
OK<StorekeeperOperationResponse, List<StorekeeperViewModel>>(data);
|
||||||
|
|
||||||
|
public static StorekeeperOperationResponse OK(StorekeeperViewModel data) =>
|
||||||
|
OK<StorekeeperOperationResponse, StorekeeperViewModel>(data);
|
||||||
|
|
||||||
|
public static StorekeeperOperationResponse NoContent() => NoContent<StorekeeperOperationResponse>();
|
||||||
|
|
||||||
|
public static StorekeeperOperationResponse NotFound(string message) =>
|
||||||
|
NotFound<StorekeeperOperationResponse>(message);
|
||||||
|
|
||||||
|
public static StorekeeperOperationResponse BadRequest(string message) =>
|
||||||
|
BadRequest<StorekeeperOperationResponse>(message);
|
||||||
|
|
||||||
|
public static StorekeeperOperationResponse InternalServerError(string message) =>
|
||||||
|
InternalServerError<StorekeeperOperationResponse>(message);
|
||||||
|
}
|
||||||
@@ -6,4 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
23
TheBank/BankContracts/BindingModels/ClerkBindingModel.cs
Normal file
23
TheBank/BankContracts/BindingModels/ClerkBindingModel.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель ответа от клиента для клерка
|
||||||
|
/// </summary>
|
||||||
|
public class ClerkBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Surname { get; set; }
|
||||||
|
|
||||||
|
public string? MiddleName { get; set; }
|
||||||
|
|
||||||
|
public string? Login { get; set; }
|
||||||
|
|
||||||
|
public string? Password { get; set; }
|
||||||
|
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
}
|
||||||
18
TheBank/BankContracts/BindingModels/ClientBindingModel.cs
Normal file
18
TheBank/BankContracts/BindingModels/ClientBindingModel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class ClientBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Surname { get; set; }
|
||||||
|
|
||||||
|
public decimal Balance { get; set; }
|
||||||
|
|
||||||
|
public string? ClerkId { get; set; }
|
||||||
|
|
||||||
|
public List<DepositClientBindingModel>? DepositClients { get; set; }
|
||||||
|
|
||||||
|
public List<ClientCreditProgramBindingModel>? CreditProgramClients { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class ClientCreditProgramBindingModel
|
||||||
|
{
|
||||||
|
public string? CreditProgramId { get; set; }
|
||||||
|
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class CreditProgramBindingModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public decimal MaxCost { get; set; }
|
||||||
|
|
||||||
|
public required string StorekeeperId { get; set; }
|
||||||
|
|
||||||
|
public required string PeriodId { get; set; }
|
||||||
|
|
||||||
|
public List<CreditProgramCurrencyBindingModel>? CurrencyCreditPrograms { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class CreditProgramCurrencyBindingModel
|
||||||
|
{
|
||||||
|
public string? CreditProgramId { get; set; }
|
||||||
|
|
||||||
|
public string? CurrencyId { get; set; }
|
||||||
|
}
|
||||||
16
TheBank/BankContracts/BindingModels/CurrencyBindingModel.cs
Normal file
16
TheBank/BankContracts/BindingModels/CurrencyBindingModel.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class CurrencyBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Abbreviation { get; set; }
|
||||||
|
|
||||||
|
public decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public string? StorekeeperId { get; set; }
|
||||||
|
}
|
||||||
19
TheBank/BankContracts/BindingModels/DepositBindingModel.cs
Normal file
19
TheBank/BankContracts/BindingModels/DepositBindingModel.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
|
||||||
|
public class DepositBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public float InterestRate { get; set; }
|
||||||
|
|
||||||
|
public decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public int Period { get; set; }
|
||||||
|
|
||||||
|
public string? ClerkId { get; set; }
|
||||||
|
|
||||||
|
public List<DepositClientBindingModel>? DepositClients { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class DepositClientBindingModel
|
||||||
|
{
|
||||||
|
public string? DepositId { get; set; }
|
||||||
|
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class DepositCurrencyBindingModel
|
||||||
|
{
|
||||||
|
public string? DepositId { get; set; }
|
||||||
|
|
||||||
|
public string? CurrencyId { get; set; }
|
||||||
|
}
|
||||||
15
TheBank/BankContracts/BindingModels/PeriodBindingModel.cs
Normal file
15
TheBank/BankContracts/BindingModels/PeriodBindingModel.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель ответа от клиента для срока
|
||||||
|
/// </summary>
|
||||||
|
public class PeriodBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public DateTime StartTime { get; set; }
|
||||||
|
|
||||||
|
public DateTime EndTime { get; set; }
|
||||||
|
|
||||||
|
public string? StorekeeperId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class ReplenishmentBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public decimal Amount { get; set; }
|
||||||
|
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
public string? DepositId { get; set; }
|
||||||
|
|
||||||
|
public string? ClerkId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace BankContracts.BindingModels;
|
||||||
|
|
||||||
|
public class StorekeeperBindingModel
|
||||||
|
{
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Surname { get; set; }
|
||||||
|
|
||||||
|
public string? MiddleName { get; set; }
|
||||||
|
|
||||||
|
public string? Login { get; set; }
|
||||||
|
|
||||||
|
public string? Password { get; set; }
|
||||||
|
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ namespace BankContracts.BusinessLogicContracts;
|
|||||||
|
|
||||||
public interface ICurrencyBusinessLogicContract
|
public interface ICurrencyBusinessLogicContract
|
||||||
{
|
{
|
||||||
List<CurrencyDataModel> GetAllCurrencys();
|
List<CurrencyDataModel> GetAllCurrencies();
|
||||||
|
|
||||||
List<CurrencyDataModel> GetCurrencyByStorekeeper(string storekeeperId);
|
List<CurrencyDataModel> GetCurrencyByStorekeeper(string storekeeperId);
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ public interface IPeriodBusinessLogicContract
|
|||||||
|
|
||||||
List<PeriodDataModel> GetAllPeriodsByStorekeeper(string storekeeperId);
|
List<PeriodDataModel> GetAllPeriodsByStorekeeper(string storekeeperId);
|
||||||
|
|
||||||
List<PeriodDataModel> GetAllPeriodsByStartTime(DateTime fromDate, DateTime toDate);
|
List<PeriodDataModel> GetAllPeriodsByStartTime(DateTime fromDate);
|
||||||
|
|
||||||
List<PeriodDataModel> GetAllPeriodsByEndTime(DateTime fromDate, DateTime toDate);
|
List<PeriodDataModel> GetAllPeriodsByEndTime(DateTime toDate);
|
||||||
|
|
||||||
void InsertPeriod(PeriodDataModel periodataModel);
|
void InsertPeriod(PeriodDataModel periodataModel);
|
||||||
|
|
||||||
|
|||||||
49
TheBank/BankContracts/Infrastructure/OperationResponse.cs
Normal file
49
TheBank/BankContracts/Infrastructure/OperationResponse.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankContracts.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// класс для http ответов
|
||||||
|
/// </summary>
|
||||||
|
public class OperationResponse
|
||||||
|
{
|
||||||
|
protected HttpStatusCode StatusCode { get; set; }
|
||||||
|
|
||||||
|
protected object? Result { get; set; }
|
||||||
|
|
||||||
|
public IActionResult GetResponse(HttpRequest request, HttpResponse response)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
|
ArgumentNullException.ThrowIfNull(response);
|
||||||
|
|
||||||
|
response.StatusCode = (int)StatusCode;
|
||||||
|
|
||||||
|
if (Result is null)
|
||||||
|
{
|
||||||
|
return new StatusCodeResult((int)StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ObjectResult(Result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static TResult OK<TResult, TData>(TData data)
|
||||||
|
where TResult : OperationResponse, new() =>
|
||||||
|
new() { StatusCode = HttpStatusCode.OK, Result = data };
|
||||||
|
|
||||||
|
protected static TResult NoContent<TResult>()
|
||||||
|
where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.NoContent };
|
||||||
|
|
||||||
|
protected static TResult BadRequest<TResult>(string? errorMessage = null)
|
||||||
|
where TResult : OperationResponse, new() =>
|
||||||
|
new() { StatusCode = HttpStatusCode.BadRequest, Result = errorMessage };
|
||||||
|
|
||||||
|
protected static TResult NotFound<TResult>(string? errorMessage = null)
|
||||||
|
where TResult : OperationResponse, new() =>
|
||||||
|
new() { StatusCode = HttpStatusCode.NotFound, Result = errorMessage };
|
||||||
|
|
||||||
|
protected static TResult InternalServerError<TResult>(string? errorMessage = null)
|
||||||
|
where TResult : OperationResponse, new() =>
|
||||||
|
new() { StatusCode = HttpStatusCode.InternalServerError, Result = errorMessage };
|
||||||
|
}
|
||||||
23
TheBank/BankContracts/ViewModels/ClerkViewModel.cs
Normal file
23
TheBank/BankContracts/ViewModels/ClerkViewModel.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель представления для клерка
|
||||||
|
/// </summary>
|
||||||
|
public class ClerkViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public required string Surname { get; set; }
|
||||||
|
|
||||||
|
public required string MiddleName { get; set; }
|
||||||
|
|
||||||
|
public required string Login { get; set; }
|
||||||
|
|
||||||
|
public required string Password { get; set; }
|
||||||
|
|
||||||
|
public required string Email { get; set; }
|
||||||
|
|
||||||
|
public required string PhoneNumber { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class ClientCreditProgramViewModel
|
||||||
|
{
|
||||||
|
public required string? CreditProgramId { get; set; }
|
||||||
|
|
||||||
|
public required string? ClientId { get; set; }
|
||||||
|
}
|
||||||
18
TheBank/BankContracts/ViewModels/ClientViewModel.cs
Normal file
18
TheBank/BankContracts/ViewModels/ClientViewModel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class ClientViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public required string Surname { get; set; }
|
||||||
|
|
||||||
|
public required decimal Balance { get; set; }
|
||||||
|
|
||||||
|
public required string ClerkId { get; set; }
|
||||||
|
|
||||||
|
public required List<DepositClientViewModel> DepositClients { get; set; }
|
||||||
|
|
||||||
|
public required List<ClientCreditProgramViewModel>? CreditProgramClients { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class CreditProgramCurrencyViewModel
|
||||||
|
{
|
||||||
|
public required string CreditProgramId { get; set; }
|
||||||
|
|
||||||
|
public required string CurrencyId { get; set; }
|
||||||
|
}
|
||||||
21
TheBank/BankContracts/ViewModels/CreditProgramViewModel.cs
Normal file
21
TheBank/BankContracts/ViewModels/CreditProgramViewModel.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель представления для кредитной программы
|
||||||
|
/// </summary>
|
||||||
|
public class CreditProgramViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public decimal MaxCost { get; set; }
|
||||||
|
|
||||||
|
public required string StorekeeperId { get; set; }
|
||||||
|
|
||||||
|
public required string PeriodId { get; set; }
|
||||||
|
|
||||||
|
public required List<CreditProgramCurrencyViewModel>? CurrencyCreditPrograms { get; set; }
|
||||||
|
}
|
||||||
14
TheBank/BankContracts/ViewModels/CurrencyViewModel.cs
Normal file
14
TheBank/BankContracts/ViewModels/CurrencyViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class CurrencyViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public required string Abbreviation { get; set; }
|
||||||
|
|
||||||
|
public required decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public required string StorekeeperId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class DepositClientViewModel
|
||||||
|
{
|
||||||
|
public required string DepositId { get; set; }
|
||||||
|
|
||||||
|
public required string ClientId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class DepositCurrencyViewModel
|
||||||
|
{
|
||||||
|
public required string DepositId { get; set; }
|
||||||
|
|
||||||
|
public required string CurrencyId { get; set; }
|
||||||
|
}
|
||||||
20
TheBank/BankContracts/ViewModels/DepositViewModel.cs
Normal file
20
TheBank/BankContracts/ViewModels/DepositViewModel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель представления для вклада
|
||||||
|
/// </summary>
|
||||||
|
public class DepositViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required float InterestRate { get; set; }
|
||||||
|
|
||||||
|
public required decimal Cost { get; set; }
|
||||||
|
|
||||||
|
public required int Period { get; set; }
|
||||||
|
|
||||||
|
public required string ClerkId { get; set; }
|
||||||
|
|
||||||
|
public required List<DepositClientViewModel>? DepositClients { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
15
TheBank/BankContracts/ViewModels/PeriodViewModel.cs
Normal file
15
TheBank/BankContracts/ViewModels/PeriodViewModel.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// модель представления для срока
|
||||||
|
/// </summary>
|
||||||
|
public class PeriodViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public DateTime StartTime { get; set; }
|
||||||
|
|
||||||
|
public DateTime EndTime { get; set; }
|
||||||
|
|
||||||
|
public required string StorekeeperId { get; set; }
|
||||||
|
}
|
||||||
14
TheBank/BankContracts/ViewModels/ReplenishmentViewModel.cs
Normal file
14
TheBank/BankContracts/ViewModels/ReplenishmentViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class ReplenishmentViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required decimal Amount { get; set; }
|
||||||
|
|
||||||
|
public required DateTime Date { get; set; }
|
||||||
|
|
||||||
|
public required string DepositId { get; set; }
|
||||||
|
|
||||||
|
public required string ClerkId { get; set; }
|
||||||
|
}
|
||||||
20
TheBank/BankContracts/ViewModels/StorekeeperViewModel.cs
Normal file
20
TheBank/BankContracts/ViewModels/StorekeeperViewModel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace BankContracts.ViewModels;
|
||||||
|
|
||||||
|
public class StorekeeperViewModel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public required string Surname { get; set; }
|
||||||
|
|
||||||
|
public required string MiddleName { get; set; }
|
||||||
|
|
||||||
|
public required string Login { get; set; }
|
||||||
|
|
||||||
|
public required string Password { get; set; }
|
||||||
|
|
||||||
|
public required string Email { get; set; }
|
||||||
|
|
||||||
|
public required string PhoneNumber { get; set; }
|
||||||
|
}
|
||||||
@@ -20,4 +20,8 @@
|
|||||||
<InternalsVisibleTo Include="BankTests" />
|
<InternalsVisibleTo Include="BankTests" />
|
||||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="BankWebApi" />
|
||||||
|
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace BankDatabase.Models;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BankDatabase.Models;
|
|
||||||
|
|
||||||
class DepositCurrency
|
class DepositCurrency
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using BankContracts.DataModels;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace BankDatabase.Models;
|
namespace BankDatabase.Models;
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,18 @@
|
|||||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||||
<PackageReference Include="EntityFramework" Version="5.0.0" />
|
<PackageReference Include="EntityFramework" Version="5.0.0" />
|
||||||
<PackageReference Include="EntityFramework.ru" Version="5.0.0" />
|
<PackageReference Include="EntityFramework.ru" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.4" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||||
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||||
<ProjectReference Include="..\BankDatabase\BankDatabase.csproj" />
|
<ProjectReference Include="..\BankDatabase\BankDatabase.csproj" />
|
||||||
|
<ProjectReference Include="..\BankWebApi\BankWebApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace BankTests.Infrastructure;
|
|||||||
internal class ConfigurationDatabase : IConfigurationDatabase
|
internal class ConfigurationDatabase : IConfigurationDatabase
|
||||||
{
|
{
|
||||||
public string ConnectionString =>
|
public string ConnectionString =>
|
||||||
"Host=127.0.0.1;Port=5432;Database=TitanicTest;Username=postgres;Password=admin123;Include Error Detail=true";
|
"Host=127.0.0.1;Port=5432;Database=TitanicTest;Username=postgres;Password=postgres;Include Error Detail=true";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankTests.Infrastructure;
|
||||||
|
|
||||||
|
internal class CustomWebApplicationFactory<TProgram> : WebApplicationFactory<TProgram>
|
||||||
|
where TProgram : class
|
||||||
|
{
|
||||||
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
var databaseConfig = services.SingleOrDefault(x => x.ServiceType == typeof(IConfigurationDatabase));
|
||||||
|
if (databaseConfig is not null)
|
||||||
|
services.Remove(databaseConfig);
|
||||||
|
|
||||||
|
var loggerFactory = services.SingleOrDefault(x => x.ServiceType == typeof(LoggerFactory));
|
||||||
|
if (loggerFactory is not null)
|
||||||
|
services.Remove(loggerFactory);
|
||||||
|
|
||||||
|
services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.UseEnvironment("Development");
|
||||||
|
|
||||||
|
base.ConfigureWebHost(builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -170,7 +170,7 @@ internal class CreditProgramStorageContractTests : BaseStorageContractTest
|
|||||||
Assert.That(actual.StorekeeperId, Is.EqualTo(expected.StorekeeperId));
|
Assert.That(actual.StorekeeperId, Is.EqualTo(expected.StorekeeperId));
|
||||||
Assert.That(actual.PeriodId, Is.EqualTo(expected.PeriodId));
|
Assert.That(actual.PeriodId, Is.EqualTo(expected.PeriodId));
|
||||||
});
|
});
|
||||||
if (actual.Currencies is not null)
|
if (actual.Currencies is not null && actual.Currencies.Count > 0)
|
||||||
{
|
{
|
||||||
Assert.That(expected.CurrencyCreditPrograms, Is.Not.Null);
|
Assert.That(expected.CurrencyCreditPrograms, Is.Not.Null);
|
||||||
Assert.That(
|
Assert.That(
|
||||||
@@ -210,7 +210,7 @@ internal class CreditProgramStorageContractTests : BaseStorageContractTest
|
|||||||
Assert.That(actual.StorekeeperId, Is.EqualTo(expected.StorekeeperId));
|
Assert.That(actual.StorekeeperId, Is.EqualTo(expected.StorekeeperId));
|
||||||
Assert.That(actual.PeriodId, Is.EqualTo(expected.PeriodId));
|
Assert.That(actual.PeriodId, Is.EqualTo(expected.PeriodId));
|
||||||
});
|
});
|
||||||
if (actual.CurrencyCreditPrograms is not null)
|
if (actual.CurrencyCreditPrograms is not null && actual.CurrencyCreditPrograms.Count > 0)
|
||||||
{
|
{
|
||||||
Assert.That(expected.Currencies, Is.Not.Null);
|
Assert.That(expected.Currencies, Is.Not.Null);
|
||||||
Assert.That(
|
Assert.That(
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using BankDatabase;
|
||||||
|
using BankTests.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
|
using Microsoft.AspNetCore.TestHost;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace BankTests.WebApiControllersTests;
|
||||||
|
|
||||||
|
internal class BaseWebApiControllerTest
|
||||||
|
{
|
||||||
|
private WebApplicationFactory<Program> _webApplication;
|
||||||
|
|
||||||
|
protected HttpClient HttpClient { get; private set; }
|
||||||
|
|
||||||
|
protected BankDbContext BankDbContext { get; private set; }
|
||||||
|
|
||||||
|
protected static readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
|
||||||
|
|
||||||
|
[OneTimeSetUp]
|
||||||
|
public void OneTimeSetUp()
|
||||||
|
{
|
||||||
|
_webApplication = new CustomWebApplicationFactory<Program>();
|
||||||
|
HttpClient = _webApplication
|
||||||
|
.WithWebHostBuilder(builder =>
|
||||||
|
{
|
||||||
|
builder.ConfigureTestServices(services =>
|
||||||
|
{
|
||||||
|
using var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
services.AddSingleton(loggerFactory);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.CreateClient();
|
||||||
|
|
||||||
|
var request = HttpClient.GetAsync("/login/user").GetAwaiter().GetResult();
|
||||||
|
var data = request.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||||
|
HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {data}");
|
||||||
|
|
||||||
|
BankDbContext = _webApplication.Services.GetRequiredService<BankDbContext>();
|
||||||
|
BankDbContext.Database.EnsureDeleted();
|
||||||
|
BankDbContext.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
[OneTimeTearDown]
|
||||||
|
public void OneTimeTearDown()
|
||||||
|
{
|
||||||
|
BankDbContext?.Database.EnsureDeleted();
|
||||||
|
BankDbContext?.Dispose();
|
||||||
|
HttpClient?.Dispose();
|
||||||
|
_webApplication?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static async Task<T?> GetModelFromResponseAsync<T>(HttpResponseMessage response) =>
|
||||||
|
JsonSerializer.Deserialize<T>(await response.Content.ReadAsStringAsync(), JsonSerializerOptions);
|
||||||
|
|
||||||
|
protected static StringContent MakeContent(object model) =>
|
||||||
|
new(JsonSerializer.Serialize(model), Encoding.UTF8, "application/json");
|
||||||
|
}
|
||||||
177
TheBank/BankTests/WebApiControllersTests/ClerkControllerTests.cs
Normal file
177
TheBank/BankTests/WebApiControllersTests/ClerkControllerTests.cs
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
using BankDatabase.Models;
|
||||||
|
using BankTests.Infrastructure;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace BankTests.WebApiControllersTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ClerkControllerTests : BaseWebApiControllerTest
|
||||||
|
{
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown()
|
||||||
|
{
|
||||||
|
BankDbContext.RemoveClerksFromDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetAllRecords_WhenHaveRecords_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var clerk1 = BankDbContext.InsertClerkToDatabaseAndReturn(name: "Иван", surname: "Иванов", email: "ivanov1@mail.com", login: "zal***", phone: "+7-777-777-78-90");
|
||||||
|
var clerk2 = BankDbContext.InsertClerkToDatabaseAndReturn(name: "Петр", surname: "Петров", email: "petrov2@mail.com", login: "nepupkin", phone: "+7-777-777-78-91");
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync("/api/clerks");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
var data = await GetModelFromResponseAsync<List<ClerkViewModel>>(response);
|
||||||
|
Assert.That(data, Is.Not.Null);
|
||||||
|
Assert.That(data, Has.Count.EqualTo(2));
|
||||||
|
AssertElement(data.First(x => x.Id == clerk1.Id), clerk1);
|
||||||
|
AssertElement(data.First(x => x.Id == clerk2.Id), clerk2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetAllRecords_WhenNoRecords_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync("/api/clerks");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
var data = await GetModelFromResponseAsync<List<ClerkViewModel>>(response);
|
||||||
|
Assert.That(data, Is.Not.Null);
|
||||||
|
Assert.That(data, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetRecord_ById_WhenHaveRecord_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var clerk = BankDbContext.InsertClerkToDatabaseAndReturn();
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync($"/api/clerks/{clerk.Id}");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
AssertElement(await GetModelFromResponseAsync<ClerkViewModel>(response), clerk);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetRecord_ById_WhenNoRecord_ShouldNotFound_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync($"/api/clerks/{Guid.NewGuid()}");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsJsonAsync("/api/clerks", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||||
|
AssertElement(BankDbContext.GetClerkFromDatabase(model.Id!), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_WhenHaveRecordWithSameId_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
BankDbContext.InsertClerkToDatabaseAndReturn(id: model.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsJsonAsync("/api/clerks", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_WhenSendEmptyData_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsync("/api/clerks", MakeContent(string.Empty));
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Put_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
BankDbContext.InsertClerkToDatabaseAndReturn(id: model.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PutAsJsonAsync("/api/clerks", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||||
|
BankDbContext.ChangeTracker.Clear();
|
||||||
|
AssertElement(BankDbContext.GetClerkFromDatabase(model.Id!), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Put_WhenNoFoundRecord_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PutAsJsonAsync("/api/clerks", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AssertElement(ClerkViewModel? actual, Clerk expected)
|
||||||
|
{
|
||||||
|
Assert.That(actual, Is.Not.Null);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||||
|
Assert.That(actual.Name, Is.EqualTo(expected.Name));
|
||||||
|
Assert.That(actual.Surname, Is.EqualTo(expected.Surname));
|
||||||
|
Assert.That(actual.MiddleName, Is.EqualTo(expected.MiddleName));
|
||||||
|
Assert.That(actual.Login, Is.EqualTo(expected.Login));
|
||||||
|
Assert.That(actual.Email, Is.EqualTo(expected.Email));
|
||||||
|
Assert.That(actual.PhoneNumber, Is.EqualTo(expected.PhoneNumber));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ClerkBindingModel CreateModel(
|
||||||
|
string? id = null,
|
||||||
|
string name = "Иван",
|
||||||
|
string surname = "Иванов",
|
||||||
|
string middleName = "Иванович",
|
||||||
|
string login = "ivanov",
|
||||||
|
string password = "password",
|
||||||
|
string email = "ivanov@mail.com",
|
||||||
|
string phoneNumber = "+79999999999")
|
||||||
|
=> new()
|
||||||
|
{
|
||||||
|
Id = id ?? Guid.NewGuid().ToString(),
|
||||||
|
Name = name,
|
||||||
|
Surname = surname,
|
||||||
|
MiddleName = middleName,
|
||||||
|
Login = login,
|
||||||
|
Password = password,
|
||||||
|
Email = email,
|
||||||
|
PhoneNumber = phoneNumber
|
||||||
|
};
|
||||||
|
|
||||||
|
private static void AssertElement(Clerk? actual, ClerkBindingModel expected)
|
||||||
|
{
|
||||||
|
Assert.That(actual, Is.Not.Null);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||||
|
Assert.That(actual.Name, Is.EqualTo(expected.Name));
|
||||||
|
Assert.That(actual.Surname, Is.EqualTo(expected.Surname));
|
||||||
|
Assert.That(actual.MiddleName, Is.EqualTo(expected.MiddleName));
|
||||||
|
Assert.That(actual.Login, Is.EqualTo(expected.Login));
|
||||||
|
Assert.That(actual.Email, Is.EqualTo(expected.Email));
|
||||||
|
Assert.That(actual.PhoneNumber, Is.EqualTo(expected.PhoneNumber));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
using BankDatabase;
|
||||||
|
using BankDatabase.Models;
|
||||||
|
using BankTests.Infrastructure;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace BankTests.WebApiControllersTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ClientControllerTests : BaseWebApiControllerTest
|
||||||
|
{
|
||||||
|
private Clerk _clerk;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
_clerk = BankDbContext.InsertClerkToDatabaseAndReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown()
|
||||||
|
{
|
||||||
|
BankDbContext.RemoveClientsFromDatabase();
|
||||||
|
BankDbContext.RemoveClerksFromDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetList_WhenHaveRecords_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var client1 = BankDbContext.InsertClientToDatabaseAndReturn(name: "Иван", surname: "Иванов", clerkId: _clerk.Id);
|
||||||
|
var client2 = BankDbContext.InsertClientToDatabaseAndReturn(name: "Петр", surname: "Петров", clerkId: _clerk.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync("/api/clients/getrecords");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
var data = await GetModelFromResponseAsync<List<ClientViewModel>>(response);
|
||||||
|
Assert.That(data, Is.Not.Null);
|
||||||
|
Assert.That(data, Has.Count.EqualTo(2));
|
||||||
|
AssertElement(data.First(x => x.Id == client1.Id), client1);
|
||||||
|
AssertElement(data.First(x => x.Id == client2.Id), client2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetList_WhenNoRecords_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync("/api/clients/getrecords");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
var data = await GetModelFromResponseAsync<List<ClientViewModel>>(response);
|
||||||
|
Assert.That(data, Is.Not.Null);
|
||||||
|
Assert.That(data, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetElement_ById_WhenHaveRecord_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var client = BankDbContext.InsertClientToDatabaseAndReturn(clerkId: _clerk.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync($"/api/clients/getrecord/{client.Id}");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
AssertElement(await GetModelFromResponseAsync<ClientViewModel>(response), client);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetElement_ById_WhenNoRecord_ShouldNotFound_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.GetAsync($"/api/clients/getrecord/{Guid.NewGuid()}");
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsJsonAsync("/api/clients/register", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||||
|
AssertElement(BankDbContext.GetClientFromDatabase(model.Id!), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_WhenHaveRecordWithSameId_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
BankDbContext.InsertClientToDatabaseAndReturn(id: model.Id,clerkId: _clerk.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsJsonAsync("/api/clients/register", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Post_WhenSendEmptyData_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PostAsync("/api/clients/register", MakeContent(string.Empty));
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Put_ShouldSuccess_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
BankDbContext.InsertClientToDatabaseAndReturn(id: model.Id, clerkId: _clerk.Id);
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PutAsJsonAsync("/api/clients/changeinfo", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||||
|
BankDbContext.ChangeTracker.Clear();
|
||||||
|
AssertElement(BankDbContext.GetClientFromDatabase(model.Id!), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ChangeInfo_WhenNoFoundRecord_ShouldBadRequest_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = CreateModel();
|
||||||
|
// Act
|
||||||
|
var response = await HttpClient.PutAsJsonAsync("/api/clients/changeinfo", model);
|
||||||
|
// Assert
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AssertElement(ClientViewModel? actual, Client expected)
|
||||||
|
{
|
||||||
|
Assert.That(actual, Is.Not.Null);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||||
|
Assert.That(actual.Name, Is.EqualTo(expected.Name));
|
||||||
|
Assert.That(actual.Surname, Is.EqualTo(expected.Surname));
|
||||||
|
Assert.That(actual.Balance, Is.EqualTo(expected.Balance));
|
||||||
|
Assert.That(actual.ClerkId, Is.EqualTo(expected.ClerkId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ClientBindingModel CreateModel(string? id = null, string name = "Иван", string surname = "Иванов", decimal balance = 1000, string? clerkId = null)
|
||||||
|
=> new()
|
||||||
|
{
|
||||||
|
Id = id ?? Guid.NewGuid().ToString(),
|
||||||
|
Name = name,
|
||||||
|
Surname = surname,
|
||||||
|
Balance = balance,
|
||||||
|
ClerkId = clerkId
|
||||||
|
};
|
||||||
|
|
||||||
|
private static void AssertElement(Client? actual, ClientBindingModel expected)
|
||||||
|
{
|
||||||
|
Assert.That(actual, Is.Not.Null);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||||
|
Assert.That(actual.Name, Is.EqualTo(expected.Name));
|
||||||
|
Assert.That(actual.Surname, Is.EqualTo(expected.Surname));
|
||||||
|
Assert.That(actual.Balance, Is.EqualTo(expected.Balance));
|
||||||
|
Assert.That(actual.ClerkId, Is.EqualTo(expected.ClerkId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
173
TheBank/BankWebApi/Adapters/ClerkAdapter.cs
Normal file
173
TheBank/BankWebApi/Adapters/ClerkAdapter.cs
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class ClerkAdapter : IClerkAdapter
|
||||||
|
{
|
||||||
|
private readonly IClerkBusinessLogicContract _clerkBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public ClerkAdapter(IClerkBusinessLogicContract clerkBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_clerkBusinessLogicContract = clerkBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<ClerkBindingModel, ClerkDataModel>();
|
||||||
|
cfg.CreateMap<ClerkDataModel, ClerkViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClerkOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ClerkOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _clerkBusinessLogicContract
|
||||||
|
.GetAllClerks()
|
||||||
|
.Select(x => _mapper.Map<ClerkViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ClerkOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClerkOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClerkOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClerkOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ClerkOperationResponse.OK(
|
||||||
|
_mapper.Map<ClerkViewModel>(_clerkBusinessLogicContract.GetClerkByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClerkOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ClerkOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClerkOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClerkOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClerkOperationResponse RegisterClerk(ClerkBindingModel clerkModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_clerkBusinessLogicContract.InsertClerk(_mapper.Map<ClerkDataModel>(clerkModel));
|
||||||
|
return ClerkOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClerkOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ClerkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ClerkOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClerkOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClerkOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClerkOperationResponse ChangeClerkInfo(ClerkBindingModel clerkModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_clerkBusinessLogicContract.UpdateClerk(_mapper.Map<ClerkDataModel>(clerkModel));
|
||||||
|
return ClerkOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClerkOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ClerkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ClerkOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {clerkModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ClerkOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClerkOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClerkOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
209
TheBank/BankWebApi/Adapters/ClientAdapter.cs
Normal file
209
TheBank/BankWebApi/Adapters/ClientAdapter.cs
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class ClientAdapter : IClientAdapter
|
||||||
|
{
|
||||||
|
private readonly IClientBusinessLogicContract _clientBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public ClientAdapter(IClientBusinessLogicContract clientBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_clientBusinessLogicContract = clientBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<ClientBindingModel, ClientDataModel>();
|
||||||
|
cfg.CreateMap<DepositDataModel, DepositViewModel>();
|
||||||
|
cfg.CreateMap<ClientCreditProgramBindingModel, ClientCreditProgramDataModel>();
|
||||||
|
cfg.CreateMap<ClientCreditProgramDataModel, ClientCreditProgramViewModel>();
|
||||||
|
cfg.CreateMap<DepositClientBindingModel, DepositClientDataModel>();
|
||||||
|
cfg.CreateMap<DepositClientDataModel, DepositClientViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ClientOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _clientBusinessLogicContract
|
||||||
|
.GetAllClients()
|
||||||
|
.Select(x => _mapper.Map<ClientViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ClientOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClientOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClientOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ClientOperationResponse.OK(
|
||||||
|
_mapper.Map<ClientViewModel>(_clientBusinessLogicContract.GetClientByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClientOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ClientOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClientOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClientOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientOperationResponse RegisterClient(ClientBindingModel clientModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_clientBusinessLogicContract.InsertClient(_mapper.Map<ClientDataModel>(clientModel));
|
||||||
|
return ClientOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClientOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ClientOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ClientOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClientOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClientOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientOperationResponse ChangeClientInfo(ClientBindingModel clientModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_clientBusinessLogicContract.UpdateClient(_mapper.Map<ClientDataModel>(clientModel));
|
||||||
|
return ClientOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ClientOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ClientOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ClientOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {clientModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ClientOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClientOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClientOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientOperationResponse GetListByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ClientOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _clientBusinessLogicContract
|
||||||
|
.GetClientByClerk(clerkId)
|
||||||
|
.Select(x => _mapper.Map<ClientViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ClientOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ClientOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ClientOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
238
TheBank/BankWebApi/Adapters/CreditProgramAdapter.cs
Normal file
238
TheBank/BankWebApi/Adapters/CreditProgramAdapter.cs
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
using BankDatabase.Models;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class CreditProgramAdapter : ICreditProgramAdapter
|
||||||
|
{
|
||||||
|
private readonly ICreditProgramBusinessLogicContract _creditProgramBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public CreditProgramAdapter(ICreditProgramBusinessLogicContract creditProgramBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_creditProgramBusinessLogicContract = creditProgramBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<CreditProgramBindingModel, CreditProgramDataModel>();
|
||||||
|
cfg.CreateMap<CreditProgramDataModel, CreditProgramViewModel>();
|
||||||
|
cfg.CreateMap<CreditProgramCurrencyBindingModel, CreditProgramCurrencyDataModel>();
|
||||||
|
cfg.CreateMap<CreditProgramCurrencyDataModel, CreditProgramCurrencyViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CreditProgramOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _creditProgramBusinessLogicContract
|
||||||
|
.GetAllCreditPrograms()
|
||||||
|
.Select(x => _mapper.Map<CreditProgramViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return CreditProgramOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CreditProgramOperationResponse.OK(
|
||||||
|
_mapper.Map<CreditProgramViewModel>(_creditProgramBusinessLogicContract.GetCreditProgramByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return CreditProgramOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramOperationResponse RegisterCreditProgram(CreditProgramBindingModel creditProgramModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_creditProgramBusinessLogicContract.InsertCreditProgram(_mapper.Map<CreditProgramDataModel>(creditProgramModel));
|
||||||
|
return CreditProgramOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public CreditProgramOperationResponse ChangeCreditProgramInfo(CreditProgramBindingModel creditProgramModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_creditProgramBusinessLogicContract.UpdateCreditProgram(_mapper.Map<CreditProgramDataModel>(creditProgramModel));
|
||||||
|
return CreditProgramOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {creditProgramModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramOperationResponse GetListByPeriod(string periodId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CreditProgramOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _creditProgramBusinessLogicContract
|
||||||
|
.GetCreditProgramByPeriod(periodId)
|
||||||
|
.Select(x => _mapper.Map<CreditProgramViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return CreditProgramOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramOperationResponse GetListByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CreditProgramOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _creditProgramBusinessLogicContract
|
||||||
|
.GetCreditProgramByStorekeeper(storekeeperId)
|
||||||
|
.Select(x => _mapper.Map<CreditProgramViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return CreditProgramOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CreditProgramOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
206
TheBank/BankWebApi/Adapters/CurrencyAdapter.cs
Normal file
206
TheBank/BankWebApi/Adapters/CurrencyAdapter.cs
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
using BankDatabase.Models;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class CurrencyAdapter : ICurrencyAdapter
|
||||||
|
{
|
||||||
|
private readonly ICurrencyBusinessLogicContract _currencyBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public CurrencyAdapter(ICurrencyBusinessLogicContract currencyBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_currencyBusinessLogicContract = currencyBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<CurrencyBindingModel, CurrencyDataModel>();
|
||||||
|
cfg.CreateMap<CurrencyDataModel, CurrencyViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CurrencyOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _currencyBusinessLogicContract
|
||||||
|
.GetAllCurrencies()
|
||||||
|
.Select(x => _mapper.Map<CurrencyViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return CurrencyOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CurrencyOperationResponse.OK(
|
||||||
|
_mapper.Map<CurrencyViewModel>(_currencyBusinessLogicContract.GetCurrencyByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CurrencyOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return CurrencyOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyOperationResponse MakeCurrency(CurrencyBindingModel currencyModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_currencyBusinessLogicContract.InsertCurrency(_mapper.Map<CurrencyDataModel>(currencyModel));
|
||||||
|
return CurrencyOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CurrencyOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return CurrencyOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return CurrencyOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CurrencyOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyOperationResponse ChangeCurrencyInfo(CurrencyBindingModel currencyModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_currencyBusinessLogicContract.UpdateCurrency(_mapper.Map<CurrencyDataModel>(currencyModel));
|
||||||
|
return CurrencyOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return CurrencyOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return CurrencyOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return CurrencyOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {currencyModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return CurrencyOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CurrencyOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyOperationResponse GetListByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CurrencyOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _currencyBusinessLogicContract
|
||||||
|
.GetCurrencyByStorekeeper(storekeeperId)
|
||||||
|
.Select(x => _mapper.Map<CurrencyViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return CurrencyOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return CurrencyOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
203
TheBank/BankWebApi/Adapters/DepositAdapter.cs
Normal file
203
TheBank/BankWebApi/Adapters/DepositAdapter.cs
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class DepositAdapter : IDepositAdapter
|
||||||
|
{
|
||||||
|
private readonly IDepositBusinessLogicContract _depositBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public DepositAdapter(IDepositBusinessLogicContract depositBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_depositBusinessLogicContract = depositBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<DepositBindingModel, DepositDataModel>();
|
||||||
|
cfg.CreateMap<DepositDataModel, DepositViewModel>();
|
||||||
|
cfg.CreateMap<DepositCurrencyBindingModel, DepositCurrencyDataModel>();
|
||||||
|
cfg.CreateMap<DepositCurrencyDataModel, DepositCurrencyViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
public DepositOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DepositOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _depositBusinessLogicContract
|
||||||
|
.GetAllDeposits()
|
||||||
|
.Select(x => _mapper.Map<DepositViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return DepositOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return DepositOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return DepositOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DepositOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DepositOperationResponse.OK(
|
||||||
|
_mapper.Map<DepositViewModel>(_depositBusinessLogicContract.GetDepositByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return DepositOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return DepositOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return DepositOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return DepositOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DepositOperationResponse MakeDeposit(DepositBindingModel depositModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_depositBusinessLogicContract.InsertDeposit(_mapper.Map<DepositDataModel>(depositModel));
|
||||||
|
return DepositOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return DepositOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return DepositOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return DepositOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return DepositOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return DepositOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DepositOperationResponse ChangeDepositInfo(DepositBindingModel depositModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_depositBusinessLogicContract.UpdateDeposit(_mapper.Map<DepositDataModel>(depositModel));
|
||||||
|
return DepositOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return DepositOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return DepositOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return DepositOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {depositModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return DepositOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return DepositOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return DepositOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DepositOperationResponse GetListByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DepositOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _depositBusinessLogicContract
|
||||||
|
.GetDepositByClerk(clerkId)
|
||||||
|
.Select(x => _mapper.Map<DepositViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return DepositOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return DepositOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return DepositOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
275
TheBank/BankWebApi/Adapters/PeriodAdapter.cs
Normal file
275
TheBank/BankWebApi/Adapters/PeriodAdapter.cs
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class PeriodAdapter : IPeriodAdapter
|
||||||
|
{
|
||||||
|
private readonly IPeriodBusinessLogicContract _periodBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public PeriodAdapter(IPeriodBusinessLogicContract periodBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_periodBusinessLogicContract = periodBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<PeriodBindingModel, PeriodDataModel>();
|
||||||
|
cfg.CreateMap<PeriodDataModel, PeriodViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return PeriodOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _periodBusinessLogicContract
|
||||||
|
.GetAllPeriods()
|
||||||
|
.Select(x => _mapper.Map<PeriodViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return PeriodOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public PeriodOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return PeriodOperationResponse.OK(
|
||||||
|
_mapper.Map<PeriodViewModel>(_periodBusinessLogicContract.GetPeriodByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return PeriodOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return PeriodOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse GetListByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return PeriodOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _periodBusinessLogicContract
|
||||||
|
.GetAllPeriodsByStorekeeper(storekeeperId)
|
||||||
|
.Select(x => _mapper.Map<PeriodViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return PeriodOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse GetListByStartTime(DateTime fromDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return PeriodOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _periodBusinessLogicContract
|
||||||
|
.GetAllPeriodsByStartTime(fromDate)
|
||||||
|
.Select(x => _mapper.Map<PeriodViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return PeriodOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (IncorrectDatesException)
|
||||||
|
{
|
||||||
|
_logger.LogError("IncorrectDatesException");
|
||||||
|
return PeriodOperationResponse.BadRequest("Incorrect dates");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse GetListByEndTime(DateTime toDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return PeriodOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _periodBusinessLogicContract
|
||||||
|
.GetAllPeriodsByStartTime(toDate)
|
||||||
|
.Select(x => _mapper.Map<PeriodViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return PeriodOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (IncorrectDatesException)
|
||||||
|
{
|
||||||
|
_logger.LogError("IncorrectDatesException");
|
||||||
|
return PeriodOperationResponse.BadRequest("Incorrect dates");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse RegisterPeriod(PeriodBindingModel periodModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_periodBusinessLogicContract.InsertPeriod(_mapper.Map<PeriodDataModel>(periodModel));
|
||||||
|
return PeriodOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return PeriodOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return PeriodOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return PeriodOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodOperationResponse ChangePeriodInfo(PeriodBindingModel periodModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_periodBusinessLogicContract.UpdatePeriod(_mapper.Map<PeriodDataModel>(periodModel));
|
||||||
|
return PeriodOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return PeriodOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return PeriodOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return PeriodOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {periodModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return PeriodOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return PeriodOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return PeriodOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
272
TheBank/BankWebApi/Adapters/ReplenishmentAdapter.cs
Normal file
272
TheBank/BankWebApi/Adapters/ReplenishmentAdapter.cs
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class ReplenishmentAdapter : IReplenishmentAdapter
|
||||||
|
{
|
||||||
|
private readonly IReplenishmentBusinessLogicContract _replenishmentBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public ReplenishmentAdapter(IReplenishmentBusinessLogicContract replenishmentBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_replenishmentBusinessLogicContract = replenishmentBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<ReplenishmentBindingModel, ReplenishmentDataModel>();
|
||||||
|
cfg.CreateMap<ReplenishmentDataModel, ReplenishmentViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ReplenishmentOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _replenishmentBusinessLogicContract
|
||||||
|
.GetAllReplenishments()
|
||||||
|
.Select(x => _mapper.Map<ReplenishmentViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ReplenishmentOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ReplenishmentOperationResponse.OK(
|
||||||
|
_mapper.Map<ReplenishmentViewModel>(_replenishmentBusinessLogicContract.GetReplenishmentByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ReplenishmentOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse GetListByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ReplenishmentOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _replenishmentBusinessLogicContract
|
||||||
|
.GetAllReplenishmentsByClerk(clerkId)
|
||||||
|
.Select(x => _mapper.Map<ReplenishmentViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ReplenishmentOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse GetListByDeposit(string depositId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ReplenishmentOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _replenishmentBusinessLogicContract
|
||||||
|
.GetAllReplenishmentsByDeposit(depositId)
|
||||||
|
.Select(x => _mapper.Map<ReplenishmentViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ReplenishmentOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse GetListByDate(DateTime fromDate, DateTime toDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ReplenishmentOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _replenishmentBusinessLogicContract
|
||||||
|
.GetAllReplenishmentsByDate(fromDate, toDate)
|
||||||
|
.Select(x => _mapper.Map<ReplenishmentViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return ReplenishmentOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (IncorrectDatesException)
|
||||||
|
{
|
||||||
|
_logger.LogError("IncorrectDatesException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest("Incorrect dates");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse RegisterReplenishment(ReplenishmentBindingModel replenishmentModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_replenishmentBusinessLogicContract.InsertReplenishment(_mapper.Map<ReplenishmentDataModel>(replenishmentModel));
|
||||||
|
return ReplenishmentOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentOperationResponse ChangeReplenishmentInfo(ReplenishmentBindingModel replenishmentModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_replenishmentBusinessLogicContract.UpdateReplenishment(_mapper.Map<ReplenishmentDataModel>(replenishmentModel));
|
||||||
|
return ReplenishmentOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {replenishmentModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return ReplenishmentOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return ReplenishmentOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
174
TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs
Normal file
174
TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.AdapterContracts.OperationResponses;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace BankWebApi.Adapters;
|
||||||
|
|
||||||
|
public class StorekeeperAdapter : IStorekeeperAdapter
|
||||||
|
{
|
||||||
|
private readonly IStorekeeperBusinessLogicContract _storekeeperBusinessLogicContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly Mapper _mapper;
|
||||||
|
|
||||||
|
public StorekeeperAdapter(IStorekeeperBusinessLogicContract storekeeperBusinessLogicContract, ILogger logger)
|
||||||
|
{
|
||||||
|
_storekeeperBusinessLogicContract = storekeeperBusinessLogicContract;
|
||||||
|
_logger = logger;
|
||||||
|
var config = new MapperConfiguration(cfg =>
|
||||||
|
{
|
||||||
|
cfg.CreateMap<StorekeeperBindingModel, StorekeeperDataModel>();
|
||||||
|
cfg.CreateMap<StorekeeperDataModel, StorekeeperViewModel>();
|
||||||
|
});
|
||||||
|
_mapper = new Mapper(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorekeeperOperationResponse GetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return StorekeeperOperationResponse.OK(
|
||||||
|
[
|
||||||
|
.. _storekeeperBusinessLogicContract
|
||||||
|
.GetAllStorekeepers()
|
||||||
|
.Select(x => _mapper.Map<StorekeeperViewModel>(x)),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (NullListException)
|
||||||
|
{
|
||||||
|
_logger.LogError("NullListException");
|
||||||
|
return StorekeeperOperationResponse.NotFound("The list is not initialized");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage:{ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorekeeperOperationResponse GetElement(string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return StorekeeperOperationResponse.OK(
|
||||||
|
_mapper.Map<StorekeeperViewModel>(_storekeeperBusinessLogicContract.GetStorekeeperByData(data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return StorekeeperOperationResponse.NotFound($"Not found element by data {data}");
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorekeeperOperationResponse RegisterStorekeeper(StorekeeperBindingModel storekeeperModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storekeeperBusinessLogicContract.InsertStorekeeper(_mapper.Map<StorekeeperDataModel>(storekeeperModel));
|
||||||
|
return StorekeeperOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorekeeperOperationResponse ChangeStorekeeperInfo(StorekeeperBindingModel storekeeperModel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storekeeperBusinessLogicContract.UpdateStorekeeper(_mapper.Map<StorekeeperDataModel>(storekeeperModel));
|
||||||
|
return StorekeeperOperationResponse.NoContent();
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ArgumentNullException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest("Data is empty");
|
||||||
|
}
|
||||||
|
catch (ValidationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ValidationException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (ElementNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementNotFoundException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest(
|
||||||
|
$"Not found element by Id {storekeeperModel.Id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (ElementExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "ElementExistsException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
catch (StorageException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "StorageException");
|
||||||
|
return StorekeeperOperationResponse.BadRequest(
|
||||||
|
$"Error while working with data storage: {ex.InnerException!.Message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Exception");
|
||||||
|
return StorekeeperOperationResponse.InternalServerError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
TheBank/BankWebApi/AuthOptions.cs
Normal file
16
TheBank/BankWebApi/AuthOptions.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BankWebApi;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// настройки для авторизации
|
||||||
|
/// переделаем потом если не будет впадлу
|
||||||
|
/// </summary>
|
||||||
|
public class AuthOptions
|
||||||
|
{
|
||||||
|
public const string ISSUER = "Bank_AuthServer"; // издатель токена
|
||||||
|
public const string AUDIENCE = "Bank_AuthClient"; // потребитель токена
|
||||||
|
const string KEY = "banksuperpupersecret_secretsecretsecretkey!"; // ключ для шифрации
|
||||||
|
public static SymmetricSecurityKey GetSymmetricSecurityKey() => new(Encoding.UTF8.GetBytes(KEY));
|
||||||
|
}
|
||||||
36
TheBank/BankWebApi/BankWebApi.csproj
Normal file
36
TheBank/BankWebApi/BankWebApi.csproj
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BankBusinessLogic\BankBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\BankDatabase\BankDatabase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="BankTests" />
|
||||||
|
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
6
TheBank/BankWebApi/BankWebApi.http
Normal file
6
TheBank/BankWebApi/BankWebApi.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@BankWebApi_HostAddress = http://localhost:5189
|
||||||
|
|
||||||
|
GET {{BankWebApi_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
58
TheBank/BankWebApi/Controllers/ClerksController.cs
Normal file
58
TheBank/BankWebApi/Controllers/ClerksController.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class ClerksController(IClerkAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IClerkAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей клерков
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список клерков</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о клерке по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись клерка</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] ClerkBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterClerk(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] ClerkBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeClerkInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
TheBank/BankWebApi/Controllers/ClientsController.cs
Normal file
69
TheBank/BankWebApi/Controllers/ClientsController.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class ClientsController(IClientAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IClientAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей клиентов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список клиентов</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о клиенте по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись клиента</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей клиента по уникальному идентификатору клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор клерка</param>
|
||||||
|
/// <returns>список клиентов</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByClerk(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByClerk(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи клиента
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] ClientBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterClient(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи клиента
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] ClientBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeClientInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
TheBank/BankWebApi/Controllers/CreditProgramsController.cs
Normal file
80
TheBank/BankWebApi/Controllers/CreditProgramsController.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class CreditProgramsController(ICreditProgramAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ICreditProgramAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей кредитных программ
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список кредитных программ</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о кредитной программе по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись кредитной программы</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей кредитных программ по уникальному идентификатору кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор кладовщика</param>
|
||||||
|
/// <returns>список кредитных программ</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByStorekeeper(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByStorekeeper(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей кредитных программ по уникальному идентификатору периода
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор периода</param>
|
||||||
|
/// <returns>список кредитных программ</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByPeriod(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByPeriod(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи кредитной программы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] CreditProgramBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterCreditProgram(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи кредитной программы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] CreditProgramBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeCreditProgramInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
TheBank/BankWebApi/Controllers/CurrenciesController.cs
Normal file
69
TheBank/BankWebApi/Controllers/CurrenciesController.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class CurrenciesController(ICurrencyAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ICurrencyAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей валют
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список валют</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о валюте по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись вклада</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей валюте по уникальному идентификатору кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор кладовщика</param>
|
||||||
|
/// <returns>список валют</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByStorekeeper(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByStorekeeper(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи валюты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] CurrencyBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.MakeCurrency(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи валюты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] CurrencyBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeCurrencyInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
TheBank/BankWebApi/Controllers/DepositsController.cs
Normal file
69
TheBank/BankWebApi/Controllers/DepositsController.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class DepositsController(IDepositAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IDepositAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей вкладов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список вкладов</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о вкладе по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись вклада</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей вкладов по уникальному идентификатору клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор клерка</param>
|
||||||
|
/// <returns>список вкладов</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByClerk(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByClerk(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи вклада
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] DepositBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.MakeDeposit(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи вклада
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] DepositBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeDepositInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
92
TheBank/BankWebApi/Controllers/PeriodController.cs
Normal file
92
TheBank/BankWebApi/Controllers/PeriodController.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class PeriodController(IPeriodAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IPeriodAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей сроков
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список сроков</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о сроке по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись срока</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей сроков по уникальному идентификатору кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор кладовщика</param>
|
||||||
|
/// <returns>список сроков</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByStorekeeper(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByStorekeeper(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей сроков по дате начала
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">дата начала</param>
|
||||||
|
/// <returns>список сроков</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByStartTime(DateTime data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByStartTime(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей сроков по дате конца
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">дата конца</param>
|
||||||
|
/// <returns>список сроков</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByEndTime(DateTime data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByEndTime(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи срока
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] PeriodBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterPeriod(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи срока
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] PeriodBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangePeriodInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
92
TheBank/BankWebApi/Controllers/ReplenishmentsController.cs
Normal file
92
TheBank/BankWebApi/Controllers/ReplenishmentsController.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class ReplenishmentsController(IReplenishmentAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IReplenishmentAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей пополнений
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список пополнений</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о пополнени по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись пополнения</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей пополнений по уникальному идентификатору клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор клерка</param>
|
||||||
|
/// <returns>список пополнений</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByClerk(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByClerk(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей пополнений по уникальному идентификатору вклада
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор вклада</param>
|
||||||
|
/// <returns>список пополнений</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByDeposit(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByDeposit(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение записей пополнений по дате
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fromDate"></param>
|
||||||
|
/// <param name="toDate"></param>
|
||||||
|
/// <returns>список пополнений</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecordByDate(DateTime fromDate, DateTime toDate)
|
||||||
|
{
|
||||||
|
return _adapter.GetListByDate(fromDate, toDate).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи пополнения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] ReplenishmentBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterReplenishment(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи пополнения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] ReplenishmentBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeReplenishmentInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
TheBank/BankWebApi/Controllers/StorekeepersController.cs
Normal file
58
TheBank/BankWebApi/Controllers/StorekeepersController.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BindingModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BankWebApi.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class StorekeepersController(IStorekeeperAdapter adapter) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IStorekeeperAdapter _adapter = adapter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получение всех записей кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>список кладовщиков</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAllRecords()
|
||||||
|
{
|
||||||
|
return _adapter.GetList().GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получние записи о кладовщике по данным
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">уникальный идентификатор или другое поле</param>
|
||||||
|
/// <returns>запись кладовщика</returns>
|
||||||
|
[HttpGet("{data}")]
|
||||||
|
public IActionResult GetRecord(string data)
|
||||||
|
{
|
||||||
|
return _adapter.GetElement(data).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// создание записи кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">модель от пользователя</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Register([FromBody] StorekeeperBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.RegisterStorekeeper(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// изменение записи кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">новая модель</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
public IActionResult ChangeInfo([FromBody] StorekeeperBindingModel model)
|
||||||
|
{
|
||||||
|
return _adapter.ChangeStorekeeperInfo(model).GetResponse(Request, Response);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
TheBank/BankWebApi/Infrastructure/ConfigurationDatabase.cs
Normal file
14
TheBank/BankWebApi/Infrastructure/ConfigurationDatabase.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using BankContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace BankWebApi.Infrastructure;
|
||||||
|
|
||||||
|
public class ConfigurationDatabase(IConfiguration configuration) : IConfigurationDatabase
|
||||||
|
{
|
||||||
|
private readonly Lazy<DataBaseSettings> _dataBaseSettings = new(() =>
|
||||||
|
{
|
||||||
|
return configuration.GetSection("DataBaseSettings").Get<DataBaseSettings>()
|
||||||
|
?? throw new InvalidDataException("DataBaseSettings section is missing or invalid.");
|
||||||
|
});
|
||||||
|
|
||||||
|
public string ConnectionString => _dataBaseSettings.Value.ConnectionString;
|
||||||
|
}
|
||||||
6
TheBank/BankWebApi/Infrastructure/DataBaseSettings.cs
Normal file
6
TheBank/BankWebApi/Infrastructure/DataBaseSettings.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace BankWebApi.Infrastructure;
|
||||||
|
|
||||||
|
public class DataBaseSettings
|
||||||
|
{
|
||||||
|
public required string ConnectionString { get; set; }
|
||||||
|
}
|
||||||
155
TheBank/BankWebApi/Program.cs
Normal file
155
TheBank/BankWebApi/Program.cs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
using BankBusinessLogic.Implementations;
|
||||||
|
using BankContracts.AdapterContracts;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.Infrastructure;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using BankDatabase;
|
||||||
|
using BankDatabase.Implementations;
|
||||||
|
using BankWebApi;
|
||||||
|
using BankWebApi.Adapters;
|
||||||
|
using BankWebApi.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Serilog;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
using var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).CreateLogger());
|
||||||
|
builder.Services.AddSingleton(loggerFactory.CreateLogger("Any"));
|
||||||
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Bank API", Version = "v1" });
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> XML-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||||
|
var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||||
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||||
|
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JWT-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Swagger UI
|
||||||
|
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: 'Bearer {token}'",
|
||||||
|
Name = "Authorization",
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Type = SecuritySchemeType.Http,
|
||||||
|
Scheme = "bearer",
|
||||||
|
BearerFormat = "JWT"
|
||||||
|
});
|
||||||
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Reference = new OpenApiReference
|
||||||
|
{
|
||||||
|
Type = ReferenceType.SecurityScheme,
|
||||||
|
Id = "Bearer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
|
||||||
|
ValidateIssuer = true,
|
||||||
|
|
||||||
|
ValidIssuer = AuthOptions.ISSUER,
|
||||||
|
|
||||||
|
ValidateAudience = true,
|
||||||
|
|
||||||
|
ValidAudience = AuthOptions.AUDIENCE,
|
||||||
|
|
||||||
|
ValidateLifetime = true,
|
||||||
|
|
||||||
|
IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
|
||||||
|
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
|
builder.Services.AddOpenApi();
|
||||||
|
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
builder.Services.AddTransient<IClerkBusinessLogicContract, ClerkBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<IPeriodBusinessLogicContract, PeriodBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<IDepositBusinessLogicContract, DepositBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<IClientBusinessLogicContract, ClientBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<ICreditProgramBusinessLogicContract, CreditProgramBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<ICurrencyBusinessLogicContract, CurrencyBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<IStorekeeperBusinessLogicContract, StorekeeperBusinessLogicContract>();
|
||||||
|
builder.Services.AddTransient<IReplenishmentBusinessLogicContract, ReplenishmentBusinessLogicContract>();
|
||||||
|
// <20><>
|
||||||
|
builder.Services.AddTransient<BankDbContext>();
|
||||||
|
builder.Services.AddTransient<IClerkStorageContract, ClerkStorageContract>();
|
||||||
|
builder.Services.AddTransient<IPeriodStorageContract, PeriodStorageContract>();
|
||||||
|
builder.Services.AddTransient<IDepositStorageContract, DepositStorageContract>();
|
||||||
|
builder.Services.AddTransient<IClientStorageContract, ClientStorageContract>();
|
||||||
|
builder.Services.AddTransient<ICreditProgramStorageContract, CreditProgramStorageContract>();
|
||||||
|
builder.Services.AddTransient<ICurrencyStorageContract, CurrencyStorageContract>();
|
||||||
|
builder.Services.AddTransient<IStorekeeperStorageContract, StorekeeperStorageContract>();
|
||||||
|
builder.Services.AddTransient<IReplenishmentStorageContract, ReplenishmentStorageContract>();
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
builder.Services.AddTransient<IClerkAdapter, ClerkAdapter>();
|
||||||
|
builder.Services.AddTransient<IPeriodAdapter, PeriodAdapter>();
|
||||||
|
builder.Services.AddTransient<IDepositAdapter, DepositAdapter>();
|
||||||
|
builder.Services.AddTransient<IClientAdapter, ClientAdapter>();
|
||||||
|
builder.Services.AddTransient<ICreditProgramAdapter, CreditProgramAdapter>();
|
||||||
|
builder.Services.AddTransient<ICurrencyAdapter, CurrencyAdapter>();
|
||||||
|
builder.Services.AddTransient<IStorekeeperAdapter, StorekeeperAdapter>();
|
||||||
|
builder.Services.AddTransient<IReplenishmentAdapter, ReplenishmentAdapter>();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.MapOpenApi();
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bank API V1");
|
||||||
|
c.RoutePrefix = "swagger"; // Swagger UI <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> /swagger
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (app.Environment.IsProduction())
|
||||||
|
{
|
||||||
|
var dbContext = app.Services.GetRequiredService<BankDbContext>();
|
||||||
|
if (dbContext.Database.CanConnect())
|
||||||
|
{
|
||||||
|
dbContext.Database.EnsureCreated();
|
||||||
|
dbContext.Database.Migrate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.Map("/login/{username}", (string username) =>
|
||||||
|
{
|
||||||
|
return new JwtSecurityTokenHandler().WriteToken(new JwtSecurityToken(
|
||||||
|
issuer: AuthOptions.ISSUER,
|
||||||
|
audience: AuthOptions.AUDIENCE,
|
||||||
|
claims: [new(ClaimTypes.Name, username)],
|
||||||
|
expires: DateTime.UtcNow.Add(TimeSpan.FromMinutes(2)),
|
||||||
|
signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
23
TheBank/BankWebApi/Properties/launchSettings.json
Normal file
23
TheBank/BankWebApi/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5189",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7204;http://localhost:5189",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
TheBank/BankWebApi/appsettings.Development.json
Normal file
8
TheBank/BankWebApi/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
TheBank/BankWebApi/appsettings.json
Normal file
28
TheBank/BankWebApi/appsettings.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Information"
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "../logs/bank-.log",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Username} {Message:lj} {Exception} {NewLine},"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"DataBaseSettings": {
|
||||||
|
"ConnectionString": "Host=127.0.0.1;Port=5432;Database=BankTest;Username=postgres;Password=admin123;"
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankDatabase", "BankDatabas
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankTests", "BankTests\BankTests.csproj", "{7C898FC8-6BC2-41E8-9538-D42ACC263A97}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankTests", "BankTests\BankTests.csproj", "{7C898FC8-6BC2-41E8-9538-D42ACC263A97}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankWebApi", "BankWebApi\BankWebApi.csproj", "{C8A3A3BB-A096-429F-A763-5465C5CB735F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -33,6 +35,10 @@ Global
|
|||||||
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7C898FC8-6BC2-41E8-9538-D42ACC263A97}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C8A3A3BB-A096-429F-A763-5465C5CB735F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C8A3A3BB-A096-429F-A763-5465C5CB735F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C8A3A3BB-A096-429F-A763-5465C5CB735F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C8A3A3BB-A096-429F-A763-5465C5CB735F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user