feat: создание проекта бизнес логики, реализация бизнес логики для всех сущностей, имеющих контракт на реализацию этой логики, изменения в интерфесах контрактов хранилищ, для синхронизации их с бизнес логикой
This commit is contained in:
@@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для клерка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clerkStorageContract">контракт хранилища</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class ClerkBusinessLogicContract(
|
||||||
|
IClerkStorageContract clerkStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : IClerkBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IClerkStorageContract _clerkStorageContract = clerkStorageContract;
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<ClerkDataModel> GetAllClerks()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all clerks");
|
||||||
|
return _clerkStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClerkDataModel GetClerkByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Get clerk by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _clerkStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||||
|
{
|
||||||
|
return _clerkStorageContract.GetElementByPhoneNumber(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
return _clerkStorageContract.GetElementByLogin(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertClerk(ClerkDataModel clerkDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Insert clerk: {JsonSerializer.Serialize(clerkDataModel)}");
|
||||||
|
ArgumentNullException.ThrowIfNull(clerkDataModel);
|
||||||
|
clerkDataModel.Validate();
|
||||||
|
_clerkStorageContract.AddElement(clerkDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateClerk(ClerkDataModel clerkDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update clerk: {clerk}", clerkDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(clerkDataModel);
|
||||||
|
clerkDataModel.Validate();
|
||||||
|
_clerkStorageContract.UpdElement(clerkDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для клиента
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientStorageContract">контракт клиента</param>
|
||||||
|
/// <param name="clerkStorageContract">контракт клерка</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class ClientBusinessLogicContract(
|
||||||
|
IClientStorageContract clientStorageContract,
|
||||||
|
IClerkStorageContract clerkStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : IClientBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IClientStorageContract _clientStorageContract = clientStorageContract;
|
||||||
|
private readonly IClerkStorageContract _clerkStorageContract = clerkStorageContract;
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<ClientDataModel> GetAllClients()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all clerks");
|
||||||
|
return _clientStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientDataModel> GetClientByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetClientByClerk params: {clerkId}", clerkId);
|
||||||
|
if (clerkId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(clerkId));
|
||||||
|
}
|
||||||
|
if (!clerkId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field clerkId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _clientStorageContract.GetList(clerkId: clerkId)
|
||||||
|
?? throw new NullListException($"{clerkId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientDataModel GetClientByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Get client by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _clientStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertClient(ClientDataModel clientDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Insert client: {client}",
|
||||||
|
JsonSerializer.Serialize(clientDataModel)
|
||||||
|
);
|
||||||
|
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||||
|
clientDataModel.Validate();
|
||||||
|
_clientStorageContract.AddElement(clientDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateClient(ClientDataModel clientDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update client: {client}", clientDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||||
|
clientDataModel.Validate();
|
||||||
|
_clientStorageContract.UpdElement(clientDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для кредитной программы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cpStorageContract">контракт хранилища кредитной программы</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class CreditProgramBusinessLogicContract(
|
||||||
|
ICreditProgramStorageContract cpStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : ICreditProgramBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly ICreditProgramStorageContract _creditProgramStorageContract =
|
||||||
|
cpStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<CreditProgramDataModel> GetAllCreditPrograms()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all credit programs");
|
||||||
|
return _creditProgramStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreditProgramDataModel GetCreditProgramByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Get creadit program by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _creditProgramStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CreditProgramDataModel> GetCreditProgramByPeriod(string periodId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetCreditProgramByPeriod params: {periodId}", periodId);
|
||||||
|
if (periodId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(periodId));
|
||||||
|
}
|
||||||
|
if (!periodId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field periodId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _creditProgramStorageContract.GetList(periodId: periodId)
|
||||||
|
?? throw new NullListException($"{periodId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CreditProgramDataModel> GetCreditProgramByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"GetCreditProgramByStorekeeper params: {storekeeperId}",
|
||||||
|
storekeeperId
|
||||||
|
);
|
||||||
|
if (storekeeperId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(storekeeperId));
|
||||||
|
}
|
||||||
|
if (!storekeeperId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field clerkId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _creditProgramStorageContract.GetList(storekeeperId: storekeeperId)
|
||||||
|
?? throw new NullListException($"{storekeeperId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertCreditProgram(CreditProgramDataModel creditProgramDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Insert credit program: {credit program}",
|
||||||
|
JsonSerializer.Serialize(creditProgramDataModel)
|
||||||
|
);
|
||||||
|
ArgumentNullException.ThrowIfNull(creditProgramDataModel);
|
||||||
|
creditProgramDataModel.Validate();
|
||||||
|
_creditProgramStorageContract.AddElement(creditProgramDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateCreditProgram(CreditProgramDataModel creditProgramDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update credit program: {credit program}", creditProgramDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(creditProgramDataModel);
|
||||||
|
creditProgramDataModel.Validate();
|
||||||
|
_creditProgramStorageContract.UpdElement(creditProgramDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для валюты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currencyStorageContract">контракт валюты</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class CurrencyBusinessLogicContract(
|
||||||
|
ICurrencyStorageContract currencyStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : ICurrencyBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly ICurrencyStorageContract _currencyStorageContract = currencyStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<CurrencyDataModel> GetAllCurrencys()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all currencys programs");
|
||||||
|
return _currencyStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrencyDataModel GetCurrencyByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Get currencys program by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _currencyStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
return _currencyStorageContract.GetElementByAbbreviation(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CurrencyDataModel> GetCurrencyByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetCurrencyByStorekeeper params: {storekeeperId}", storekeeperId);
|
||||||
|
if (storekeeperId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(storekeeperId));
|
||||||
|
}
|
||||||
|
if (!storekeeperId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field storekeeperId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _currencyStorageContract.GetList(storekeeperId: storekeeperId)
|
||||||
|
?? throw new NullListException($"{storekeeperId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertCurrency(CurrencyDataModel currencyDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Insert currency: {currency}",
|
||||||
|
JsonSerializer.Serialize(currencyDataModel)
|
||||||
|
);
|
||||||
|
ArgumentNullException.ThrowIfNull(currencyDataModel);
|
||||||
|
currencyDataModel.Validate();
|
||||||
|
_currencyStorageContract.AddElement(currencyDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateCurrency(CurrencyDataModel currencyDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update currency: {currency}", currencyDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(currencyDataModel);
|
||||||
|
currencyDataModel.Validate();
|
||||||
|
_currencyStorageContract.UpdElement(currencyDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для вклада
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="depositStorageContract">контракт вклада</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class DepositBusinessLogicContract(
|
||||||
|
IDepositStorageContract depositStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : IDepositBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IDepositStorageContract _depositStorageContract = depositStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<DepositDataModel> GetAllDeposits()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all deposits");
|
||||||
|
return _depositStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DepositDataModel> GetDepositByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetDepositByClerk params: {clerkId}", clerkId);
|
||||||
|
if (clerkId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(clerkId));
|
||||||
|
}
|
||||||
|
if (!clerkId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field clerkId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _depositStorageContract.GetList(clerkId: clerkId)
|
||||||
|
?? throw new NullListException($"{clerkId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DepositDataModel GetDepositByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"GetDepositByData by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _depositStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
return _depositStorageContract.GetElementByName(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertDeposit(DepositDataModel depositDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Insert credit program: {credit program}",
|
||||||
|
JsonSerializer.Serialize(depositDataModel)
|
||||||
|
);
|
||||||
|
ArgumentNullException.ThrowIfNull(depositDataModel);
|
||||||
|
depositDataModel.Validate();
|
||||||
|
_depositStorageContract.AddElement(depositDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateDeposit(DepositDataModel depositDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update credit program: {credit program}", depositDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(depositDataModel);
|
||||||
|
depositDataModel.Validate();
|
||||||
|
_depositStorageContract.UpdElement(depositDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для сроков
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="periodStorageContract">контракт сроков</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class PeriodBusinessLogicContract(
|
||||||
|
IPeriodStorageContract periodStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : IPeriodBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IPeriodStorageContract _periodStorageContract = periodStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<PeriodDataModel> GetAllPeriods()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all periods");
|
||||||
|
return _periodStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PeriodDataModel> GetAllPeriodsByEndTime(DateTime fromDate, DateTime toDate)
|
||||||
|
{
|
||||||
|
if (toDate.IsDateNotOlder(toDate))
|
||||||
|
{
|
||||||
|
throw new IncorrectDatesException(fromDate, toDate);
|
||||||
|
}
|
||||||
|
return _periodStorageContract.GetList(fromDate, toDate).OrderBy(x => x.EndTime).ToList()
|
||||||
|
?? throw new NullListException(nameof(PeriodDataModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PeriodDataModel> GetAllPeriodsByStartTime(DateTime fromDate, DateTime toDate)
|
||||||
|
{
|
||||||
|
if (toDate.IsDateNotOlder(toDate))
|
||||||
|
{
|
||||||
|
throw new IncorrectDatesException(fromDate, toDate);
|
||||||
|
}
|
||||||
|
return _periodStorageContract.GetList(fromDate, toDate).OrderBy(x => x.StartTime).ToList()
|
||||||
|
?? throw new NullListException(nameof(PeriodDataModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PeriodDataModel> GetAllPeriodsByStorekeeper(string storekeeperId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetAllPeriodsByStorekeeper params: {storekeeperId}", storekeeperId);
|
||||||
|
if (storekeeperId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(storekeeperId));
|
||||||
|
}
|
||||||
|
if (!storekeeperId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field storekeeperId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _periodStorageContract.GetList(storekeeperId: storekeeperId)
|
||||||
|
?? throw new NullListException($"{storekeeperId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodDataModel GetPeriodByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"GetPeriodByData by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _periodStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertPeriod(PeriodDataModel periodataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Insert period: {period}", JsonSerializer.Serialize(periodataModel));
|
||||||
|
ArgumentNullException.ThrowIfNull(periodataModel);
|
||||||
|
periodataModel.Validate();
|
||||||
|
_periodStorageContract.AddElement(periodataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePeriod(PeriodDataModel periodataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update period: {period}", periodataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(periodataModel);
|
||||||
|
periodataModel.Validate();
|
||||||
|
_periodStorageContract.UpdElement(periodataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для пополнения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="replenishmentStorageContract">контракт пополнения</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class ReplenishmentBusinessLogicContract(
|
||||||
|
IReplenishmentStorageContract replenishmentStorageContract,
|
||||||
|
ILogger logger
|
||||||
|
) : IReplenishmentBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IReplenishmentStorageContract _replenishmentStorageContract =
|
||||||
|
replenishmentStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<ReplenishmentDataModel> GetAllReplenishments()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all replenishments");
|
||||||
|
return _replenishmentStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReplenishmentDataModel> GetAllReplenishmentsByClerk(string clerkId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetAllReplenishmentsByClerk params: {clerkId}", clerkId);
|
||||||
|
if (clerkId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(clerkId));
|
||||||
|
}
|
||||||
|
if (!clerkId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field clerkId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _replenishmentStorageContract.GetList(clerkId: clerkId)
|
||||||
|
?? throw new NullListException($"{clerkId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReplenishmentDataModel> GetAllReplenishmentsByDate(
|
||||||
|
DateTime fromDate,
|
||||||
|
DateTime toDate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (toDate.IsDateNotOlder(fromDate))
|
||||||
|
{
|
||||||
|
throw new IncorrectDatesException(fromDate, toDate);
|
||||||
|
}
|
||||||
|
return _replenishmentStorageContract.GetList(fromDate, toDate).ToList()
|
||||||
|
?? throw new NullListException(nameof(PeriodDataModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReplenishmentDataModel> GetAllReplenishmentsByDeposit(string depositId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("GetAllReplenishmentsByClerk params: {depositId}", depositId);
|
||||||
|
if (depositId.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(depositId));
|
||||||
|
}
|
||||||
|
if (!depositId.IsGuid())
|
||||||
|
{
|
||||||
|
throw new ValidationException(
|
||||||
|
"The value in the field depositId is not a unique identifier."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _replenishmentStorageContract.GetList(depositId: depositId)
|
||||||
|
?? throw new NullListException($"{depositId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplenishmentDataModel GetReplenishmentByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"GetReplenishmentByData by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _replenishmentStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertReplenishment(ReplenishmentDataModel replenishmentataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Insert period: {period}",
|
||||||
|
JsonSerializer.Serialize(replenishmentataModel)
|
||||||
|
);
|
||||||
|
ArgumentNullException.ThrowIfNull(replenishmentataModel);
|
||||||
|
replenishmentataModel.Validate();
|
||||||
|
_replenishmentStorageContract.AddElement(replenishmentataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateReplenishment(ReplenishmentDataModel replenishmentataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update period: {period}", replenishmentataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(replenishmentataModel);
|
||||||
|
replenishmentataModel.Validate();
|
||||||
|
_replenishmentStorageContract.UpdElement(replenishmentataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using BankContracts.BusinessLogicContracts;
|
||||||
|
using BankContracts.DataModels;
|
||||||
|
using BankContracts.Exceptions;
|
||||||
|
using BankContracts.Extensions;
|
||||||
|
using BankContracts.StorageContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace BankBusinessLogic.Implementations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// реализация бизнес логики для кладовщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="storekeeperStorageContract">контракт кладовщика</param>
|
||||||
|
/// <param name="logger">логгер</param>
|
||||||
|
internal class StorekeeperBusinessLogicContract(IStorekeeperStorageContract storekeeperStorageContract, ILogger logger) : IStorekeeperBusinessLogicContract
|
||||||
|
{
|
||||||
|
private readonly IStorekeeperStorageContract _storekeeperStorageContract = storekeeperStorageContract;
|
||||||
|
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
|
||||||
|
public List<StorekeeperDataModel> GetAllStorekeepers()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("get all storekeepers");
|
||||||
|
return _storekeeperStorageContract.GetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorekeeperDataModel GetStorekeeperByData(string data)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Get storekeeper by data: {data}");
|
||||||
|
if (data.IsEmpty())
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
if (data.IsGuid())
|
||||||
|
{
|
||||||
|
return _storekeeperStorageContract.GetElementById(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||||
|
{
|
||||||
|
return _storekeeperStorageContract.GetElementByPhoneNumber(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
return _storekeeperStorageContract.GetElementByLogin(data)
|
||||||
|
?? throw new ElementNotFoundException($"element not found: {data}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertStorekeeper(StorekeeperDataModel storekeeperDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Insert storekeeper: {storekeeper}", JsonSerializer.Serialize(storekeeperDataModel));
|
||||||
|
ArgumentNullException.ThrowIfNull(storekeeperDataModel);
|
||||||
|
storekeeperDataModel.Validate();
|
||||||
|
_storekeeperStorageContract.AddElement(storekeeperDataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateStorekeeper(StorekeeperDataModel storekeeperDataModel)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Update storekeeper: {storekeeper}", storekeeperDataModel);
|
||||||
|
ArgumentNullException.ThrowIfNull(storekeeperDataModel);
|
||||||
|
storekeeperDataModel.Validate();
|
||||||
|
_storekeeperStorageContract.UpdElement(storekeeperDataModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace BankContracts.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ошибка для не найденного элемента в бизнес логике и контрактах
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
public class ElementNotFoundException(string message) : Exception(message) { }
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace BankContracts.Exceptions;
|
||||||
|
|
||||||
|
public class IncorrectDatesException(DateTime from, DateTime to) : Exception($"date: {from} is older than {to}") { }
|
||||||
7
TheBank/BankContracts/Exceptions/NullListException.cs
Normal file
7
TheBank/BankContracts/Exceptions/NullListException.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace BankContracts.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Исключение для null списка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">сообщение</param>
|
||||||
|
public class NullListException(string message) : Exception(message) { }
|
||||||
12
TheBank/BankContracts/Extensions/DateTimeExtensions.cs
Normal file
12
TheBank/BankContracts/Extensions/DateTimeExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace BankContracts.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// расширение для проверки дат
|
||||||
|
/// </summary>
|
||||||
|
public static class DateTimeExtensions
|
||||||
|
{
|
||||||
|
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
||||||
|
{
|
||||||
|
return date >= olderDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface IClientStorageContract
|
public interface IClientStorageContract
|
||||||
{
|
{
|
||||||
List<ClientDataModel> GetList();
|
List<ClientDataModel> GetList(string? clerkId = null);
|
||||||
|
|
||||||
ClientDataModel? GetElementById(string id);
|
ClientDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface ICreditProgramStorageContract
|
public interface ICreditProgramStorageContract
|
||||||
{
|
{
|
||||||
List<CreditProgramDataModel> GetList();
|
List<CreditProgramDataModel> GetList(string? storekeeperId = null, string? periodId = null);
|
||||||
|
|
||||||
CreditProgramDataModel? GetElementById(string id);
|
CreditProgramDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface ICurrencyStorageContract
|
public interface ICurrencyStorageContract
|
||||||
{
|
{
|
||||||
List<CurrencyDataModel> GetList();
|
List<CurrencyDataModel> GetList(string? storekeeperId = null);
|
||||||
|
|
||||||
CurrencyDataModel? GetElementById(string id);
|
CurrencyDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface IDepositStorageContract
|
public interface IDepositStorageContract
|
||||||
{
|
{
|
||||||
List<DepositDataModel> GetList();
|
List<DepositDataModel> GetList(string? clerkId = null);
|
||||||
|
|
||||||
DepositDataModel? GetElementById(string id);
|
DepositDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface IPeriodStorageContract
|
public interface IPeriodStorageContract
|
||||||
{
|
{
|
||||||
List<PeriodDataModel> GetList(DateTime startDate, DateTime endDate);
|
List<PeriodDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? storekeeperId = null);
|
||||||
|
|
||||||
PeriodDataModel? GetElementById(string id);
|
PeriodDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BankContracts.StorageContracts;
|
|||||||
|
|
||||||
public interface IReplenishmentStorageContract
|
public interface IReplenishmentStorageContract
|
||||||
{
|
{
|
||||||
List<ReplenishmentDataModel> GetList();
|
List<ReplenishmentDataModel> GetList(DateTime? fromDate = null, DateTime? toDate = null, string? clerkId = null, string? depositId = null);
|
||||||
|
|
||||||
ReplenishmentDataModel? GetElementById(string id);
|
ReplenishmentDataModel? GetElementById(string id);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.12.35707.178 d17.12
|
VisualStudioVersion = 17.12.35707.178
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankContracts", "BankContracts\BankContracts.csproj", "{7AF1B83C-2E92-482F-8189-6FE7313134FD}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankContracts", "BankContracts\BankContracts.csproj", "{7AF1B83C-2E92-482F-8189-6FE7313134FD}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankBusinessLogic", "BankBusinessLogic\BankBusinessLogic.csproj", "{EAB70DA6-3C70-4069-B83C-D90330757C12}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -15,6 +17,10 @@ Global
|
|||||||
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EAB70DA6-3C70-4069-B83C-D90330757C12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EAB70DA6-3C70-4069-B83C-D90330757C12}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EAB70DA6-3C70-4069-B83C-D90330757C12}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EAB70DA6-3C70-4069-B83C-D90330757C12}.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