Реализации

This commit is contained in:
rakhaliullov 2025-02-22 09:34:57 +04:00
parent d683764ca5
commit 5dcbf36833
6 changed files with 360 additions and 62 deletions

View File

@ -1,31 +1,82 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
using System.Text.Json;
namespace SoftBedBusinessLogic.Implementations;
internal class CollectBusinessLogicContract : ICollectBusinessLogicContract
internal class CollectBusinessLogicContract(ICollectStorageContract collectStorageContract, ILogger logger) : ICollectBusinessLogicContract
{
public List<CollectDataModel> GetAllCollectByPeriod(DateTime fromDate, DateTime toDate)
private readonly ILogger _logger = logger;
private readonly ICollectStorageContract _collectStorageContract = collectStorageContract;
public List<CollectDataModel> GetAllCollectsByPeriod(DateTime fromDate, DateTime toDate)
{
return [];
_logger.LogInformation("GetAllCollects params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _collectStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
}
public List<CollectDataModel> GetAllCollectByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
public List<CollectDataModel> GetAllCollectsByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
{
return [];
_logger.LogInformation("GetAllCollects 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 _collectStorageContract.GetList(fromDate, toDate, workerId: workerId) ?? throw new NullListException();
}
public List<CollectDataModel> GetAllCollectsByFurnitureByPeriod(string furnitureId, DateTime fromDate, DateTime toDate)
{
return [];
_logger.LogInformation("GetAllCollects params: {buyerId}, {fromDate}, {toDate}", furnitureId, fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
if (furnitureId.IsEmpty())
{
throw new ArgumentNullException(nameof(furnitureId));
}
if (!furnitureId.IsGuid())
{
throw new ValidationException("The value in the field buyerId is not a unique identifier.");
}
return _collectStorageContract.GetList(fromDate, toDate, furnitureId: furnitureId) ?? throw new NullListException();
}
public CollectDataModel GetCollectByData(string data)
{
return new("", "", "", 0);
_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 _collectStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
public void InsertCollect(CollectDataModel collectDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(collectDataModel));
ArgumentNullException.ThrowIfNull(collectDataModel);
collectDataModel.Validate();
_collectStorageContract.AddElement(collectDataModel);
}
}

View File

@ -1,35 +1,91 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Enums;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
using System.Text.Json;
namespace SoftBedBusinessLogic.Implementations;
internal class FurnitureBusinessLogicContract : IFurnitureBusinessLogicContract
internal class FurnitureBusinessLogicContract(IFurnitureStorageContract furnitureStorageContract, ILogger logger) : IFurnitureBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IFurnitureStorageContract _furnitureStorageContract = furnitureStorageContract;
public List<FurnitureDataModel> GetAllFurniture(bool onlyActive = true)
{
return [];
_logger.LogInformation("GetAllFurniture params: {onlyActive}", onlyActive);
return _furnitureStorageContract.GetList(onlyActive) ?? throw new NullListException();
}
public List<FurnitureDataModel> GetAllFurnitureByWorkPieces(string workPiecesId, bool onlyActive = true)
{
_logger.LogInformation("GetAllSales params: {workPiecesId}", workPiecesId);
if (workPiecesId.IsEmpty())
{
throw new ArgumentNullException(nameof(workPiecesId));
}
if (!workPiecesId.IsGuid())
{
throw new ValidationException("The value in the field workPiecesId is not a unique identifier.");
}
return _furnitureStorageContract.GetList(onlyActive, workPiecesId) ?? throw new NullListException();
}
public List<FurnitureHistoryDataModel> GetFurnitureHistoryByFurniture(string furnitureId)
{
return [];
_logger.LogInformation("GetFurnitureHistoryByFurniture for {furnitureId}", furnitureId);
if (furnitureId.IsEmpty())
{
throw new ArgumentNullException(nameof(furnitureId));
}
if (!furnitureId.IsGuid())
{
throw new ValidationException("The value in the field furnitureId is not a unique identifier.");
}
return _furnitureStorageContract.GetHistoryByFurnitureId(furnitureId) ?? throw new NullListException();
}
public FurnitureDataModel GetFurnitureByData(string data)
{
return new("", "", FurnitureType.None, 0, false, []);
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _furnitureStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
return _furnitureStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
}
public void InsertFurniture(FurnitureDataModel furnitureDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(furnitureDataModel));
ArgumentNullException.ThrowIfNull(furnitureDataModel);
furnitureDataModel.Validate();
_furnitureStorageContract.AddElement(furnitureDataModel);
}
public void UpdateFurniture(FurnitureDataModel furnitureDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(furnitureDataModel));
ArgumentNullException.ThrowIfNull(furnitureDataModel);
furnitureDataModel.Validate();
_furnitureStorageContract.UpdElement(furnitureDataModel);
}
public void DeleteFurniture(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");
}
_furnitureStorageContract.DelElement(id);
}
}

View File

@ -1,40 +1,93 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Enums;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
using System.Text.Json;
namespace SoftBedBusinessLogic.Implementations;
internal class PostBusinessLogicContract : 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)
{
_logger.LogInformation("GetAllPosts params: {onlyActive}", onlyActive);
return _postStorageContract.GetList(onlyActive) ?? throw new NullListException();
}
public List<PostDataModel> GetAllDataOfPost(string postId)
{
return [];
}
public List<PostDataModel> GetAllPosts(bool onlyActive)
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
if (postId.IsEmpty())
{
return [];
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.Now);
_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)
{
}
public void RestorePost(string id)
{
_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);
}
}

View File

@ -1,21 +1,64 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
namespace SoftBedBusinessLogic.Implementations;
internal class SalaryBusinessLogicContract : ISalaryBusinessLogicContract
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
ICollectStorageContract collectStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger) : ISalaryBusinessLogicContract
{
public void CalculateSalaryByMonth(DateTime date)
{
}
private readonly ILogger _logger = logger;
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
private readonly ICollectStorageContract _collectStorageContract = collectStorageContract;
private readonly IPostStorageContract _postStorageContract = postStorageContract;
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
{
return [];
_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)
{
return [];
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();
}
public void CalculateSalaryByMonth(DateTime date)
{
_logger.LogInformation("CalculateSalaryByMonth: {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 collects = _collectStorageContract.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 + collects * 0.1;
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
}
}
}

View File

@ -1,30 +1,69 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace SoftBedBusinessLogic.Implementations;
internal class WorkPieceBusinessLogicContract : IWorkPieceBusinessLogicContract
internal class WorkPieceBusinessLogicContract(IWorkPieceStorageContract workPieceStorageContract, ILogger logger) : IWorkPieceBusinessLogicContract
{
private readonly ILogger _logger = logger;
private IWorkPieceStorageContract _workPieceStorageContract = workPieceStorageContract;
public List<WorkPieceDataModel> GetAllWorkPieces()
{
return [];
_logger.LogInformation("GetAllWorkPieces");
return _workPieceStorageContract.GetList() ?? throw new NullListException();
}
public WorkPieceDataModel GetWorkPiecesByData(string data)
{
return new("", "", 0);
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (data.IsGuid())
{
return _workPieceStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
if (Regex.IsMatch(data, @"^\d+x\d+$"))
{
return _workPieceStorageContract.GetElementBySize(data) ?? throw new ElementNotFoundException(data);
}
return _workPieceStorageContract.GetElementBySize(data) ?? throw new ElementNotFoundException(data);
}
public void InsertPost(WorkPieceDataModel workPieceDataModel)
public void InsertWorkPiece(WorkPieceDataModel workPieceDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(workPieceDataModel));
ArgumentNullException.ThrowIfNull(workPieceDataModel);
workPieceDataModel.Validate();
_workPieceStorageContract.AddElement(workPieceDataModel);
}
public void UpdatePost(WorkPieceDataModel workPieceDataModel)
public void UpdateWorkPiece(WorkPieceDataModel workPieceDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(workPieceDataModel));
ArgumentNullException.ThrowIfNull(workPieceDataModel);
workPieceDataModel.Validate();
_workPieceStorageContract.UpdElement(workPieceDataModel);
}
public void DeletePost(string id)
public void DeleteWorkPiece(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");
}
_workPieceStorageContract.DelElement(id);
}
}

View File

@ -1,43 +1,99 @@
using SoftBedContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SoftBedContracts.BusinessLogicsContracts;
using SoftBedContracts.DataModels;
using SoftBedContracts.Exceptions;
using SoftBedContracts.Extensions;
using SoftBedContracts.StoragesContracts;
using System.Text.Json;
namespace SoftBedBusinessLogic.Implementations;
internal class WorkerBusinessLogicContract : IWorkerBusinessLogicContract
internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
public List<WorkerDataModel> GetAllWorkers()
{
return [];
}
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate)
{
return [];
}
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate)
{
return [];
_logger.LogInformation("GetAllWorkers");
return _workerStorageContract.GetList() ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByPost(string postId)
{
return [];
_logger.LogInformation("GetAllWorkers params: {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 _workerStorageContract.GetList(postId) ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllWorkers params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _workerStorageContract.GetList(fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
}
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate)
{
_logger.LogInformation("GetAllWorkers params: {fromDate}, {toDate}", fromDate, toDate);
if (fromDate.IsDateNotOlder(toDate))
{
throw new IncorrectDatesException(fromDate, toDate);
}
return _workerStorageContract.GetList(fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
}
public WorkerDataModel GetWorkerByData(string data)
{
return new("", "", "", DateTime.Now, DateTime.Now);
_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)
{
_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);
}
}