Реализации, the end.
This commit is contained in:
@@ -2,29 +2,67 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class ManufacturerBusinessLogicContract(IManufacturerStorageContract manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContract
|
||||
internal class ManufacturerBusinessLogicContract(IManufacturerStorageContract
|
||||
manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IManufacturerStorageContract _manufacturerStorageContract
|
||||
= manufacturerStorageContract;
|
||||
public List<ManufacturerDataModel> GetAllManufacturers()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllManufacturers");
|
||||
return _manufacturerStorageContract.GetList() ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public ManufacturerDataModel GetManufacturerByData(string data)
|
||||
{
|
||||
return new("", "", "", "'");
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _manufacturerStorageContract.GetElementById(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _manufacturerStorageContract.GetElementByName(data) ??
|
||||
_manufacturerStorageContract.GetElementByOldName(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorageContract.AddElement(manufacturerDataModel);
|
||||
}
|
||||
public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorageContract.UpdElement(manufacturerDataModel);
|
||||
}
|
||||
public void DeleteManufacturer(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_manufacturerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,43 +2,101 @@
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
internal class PostBusinessLogicContract(IPostStorageContract
|
||||
postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract =
|
||||
postStorageContract;
|
||||
public List<PostDataModel> GetAllPosts(bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllPosts params: {onlyActive}",
|
||||
onlyActive);
|
||||
return _postStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public PostDataModel GetPostByData(string data)
|
||||
{
|
||||
return new("", "", PostType.None, 0, true, DateTime.UtcNow);
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertPost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.AddElement(postDataModel);
|
||||
}
|
||||
public void UpdatePost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
public void DeletePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
public void RestorePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Restore by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
@@ -17,28 +20,89 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
requestStorageContract;
|
||||
public List<RequestDataModel> GetAllRequestsByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllRequests params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
|
||||
}
|
||||
public List<RequestDataModel> GetAllRequestsByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllRequests params: {workerId}, {fromDate}, { toDate} ", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, workerId:
|
||||
workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<RequestDataModel> GetAllRequestsBySoftwareByPeriod(string softwareId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllRequests params: {softwareId}, {fromDate}, { toDate} ", softwareId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (softwareId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(softwareId));
|
||||
}
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, softwareId:
|
||||
softwareId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public RequestDataModel GetRequestByData(string data)
|
||||
{
|
||||
return new("", "", "", 0, false, []);
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
return _requestStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
}
|
||||
public void InsertRequest(RequestDataModel requestDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(requestDataModel));
|
||||
ArgumentNullException.ThrowIfNull(requestDataModel);
|
||||
requestDataModel.Validate();
|
||||
_requestStorageContract.AddElement(requestDataModel);
|
||||
|
||||
}
|
||||
public void CancelRequest(string id)
|
||||
{
|
||||
_logger.LogInformation("Cancel by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_requestStorageContract.DelElement(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
@@ -18,18 +20,60 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
postStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract =
|
||||
workerStorageContract;
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate,
|
||||
DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}",
|
||||
fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime
|
||||
fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, { workerId} ", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMonth(DateTime date)
|
||||
{
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month,
|
||||
DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var workers = _workerStorageContract.GetList() ?? throw new
|
||||
NullListException();
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var requests = _requestStorageContract.GetList(startDate,
|
||||
finishDate, workerId: worker.Id)?.Sum(x => x.Sum) ??
|
||||
throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId)
|
||||
??
|
||||
throw new NullListException();
|
||||
var salary = post.Salary + requests * 0.1;
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of { salary} ", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new
|
||||
SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
@@ -12,32 +15,86 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract =
|
||||
softwareStorageContract;
|
||||
public List<SoftwareDataModel> GetAllSoftwares(bool onlyActive)
|
||||
public List<SoftwareDataModel> GetAllSoftwares(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllSoftwares params: {onlyActive}", onlyActive);
|
||||
return _softwareStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<SoftwareDataModel> GetAllSoftwaresByManufacturer(string
|
||||
manufacturerId, bool onlyActive = true)
|
||||
{
|
||||
if (manufacturerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(manufacturerId));
|
||||
}
|
||||
if (!manufacturerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field manufacturerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSoftwares params: {manufacturerId}, { onlyActive} ", manufacturerId, onlyActive);
|
||||
return _softwareStorageContract.GetList(onlyActive, manufacturerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
public List<SoftwareHistoryDataModel> GetSoftwareHistoryBySoftware(string softwareId)
|
||||
{
|
||||
_logger.LogInformation("GetSoftwareHistoryBySoftware for {softwareId}", softwareId);
|
||||
if (softwareId.IsEmpty())
|
||||
{
|
||||
return [];
|
||||
throw new ArgumentNullException(nameof(softwareId));
|
||||
}
|
||||
public List<SoftwareDataModel> GetAllSoftwaresByManufacturer(string
|
||||
manufacturerId, bool onlyActive = true)
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
return [];
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
}
|
||||
public List<SoftwareHistoryDataModel> GetSoftwareHistoryBySoftware(string
|
||||
softwareId)
|
||||
return _softwareStorageContract.GetHistoryBySoftwareId(softwareId) ??
|
||||
throw new NullListException();
|
||||
|
||||
}
|
||||
public SoftwareDataModel GetSoftwareByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
return [];
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
public SoftwareDataModel GetSoftwareByData(string data)
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return new("", "", SoftwareType.None, "", 0, true);
|
||||
return _softwareStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertSoftware(SoftwareDataModel softwareDataModel)
|
||||
return _softwareStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
_softwareStorageContract.AddElement(softwareDataModel);
|
||||
}
|
||||
public void UpdateSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
_softwareStorageContract.UpdElement(softwareDataModel);
|
||||
|
||||
}
|
||||
public void DeleteSoftware(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
public void UpdateSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
}
|
||||
public void DeleteSoftware(string id)
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_softwareStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
@@ -18,34 +21,90 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
workerStorageContract;
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}",
|
||||
onlyActive);
|
||||
return _workerStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool
|
||||
onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllWorkers params: {postId}, { onlyActive},", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, postId) ?? throw
|
||||
new NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate,
|
||||
DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromBirthDate:
|
||||
fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime
|
||||
fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate:
|
||||
fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
return new("", "", "", DateTime.Now, DateTime.Now, true);
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
}
|
||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
}
|
||||
public void DeleteWorker(string id)
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_workerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -243,8 +243,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_requestStorageContract.Verify(x => x.GetList(date, date.AddDays(1),
|
||||
null, null), Times.Once);
|
||||
_requestStorageContract.Verify(x => x.GetList(date, date.AddDays(1), null, softwareId), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void GetAllRequestsBySoftwareByPeriod_ReturnEmptyList_Test()
|
||||
@@ -287,7 +286,7 @@ internal class RequestBusinessLogicContractTests
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow,
|
||||
_requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(null, DateTime.UtcNow,
|
||||
DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(string.Empty, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)),
|
||||
@@ -405,7 +404,7 @@ internal class RequestBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new RequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false,
|
||||
var record = new RequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "valid.email@example.com", 10, false,
|
||||
[new InstallationRequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_requestStorageContract.Setup(x => x.AddElement(It.IsAny<RequestDataModel>()))
|
||||
.Callback((RequestDataModel x) =>
|
||||
@@ -435,7 +434,7 @@ internal class RequestBusinessLogicContractTests
|
||||
ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,false,
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", 10,false,
|
||||
[new InstallationRequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_requestStorageContract.Verify(x => x.AddElement(It.IsAny<RequestDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -465,7 +464,7 @@ internal class RequestBusinessLogicContractTests
|
||||
InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, [new InstallationRequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", 10, false, [new InstallationRequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_requestStorageContract.Verify(x =>
|
||||
x.AddElement(It.IsAny<RequestDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user