From 2ad081dfb0fc53a77faadbd5b124bef87ee4c40c Mon Sep 17 00:00:00 2001 From: Adelina888 Date: Thu, 27 Feb 2025 15:18:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D1=80=D0=B0=D1=81=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderBusinessLogicContract.cs | 80 ++----------------- .../PostBusinessLogicContract.cs | 67 +++------------- .../ProductBusinessLogicContract.cs | 61 ++------------ .../RestaurantBusinessLogicContract.cs | 39 ++------- .../SalaryBusinessLogicContract.cs | 35 +------- .../WorkerBusinessLogicContract.cs | 69 ++-------------- 6 files changed, 38 insertions(+), 313 deletions(-) diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/OrderBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/OrderBusinessLogicContract.cs index 06f9035..3ff3b09 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/OrderBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/OrderBusinessLogicContract.cs @@ -19,99 +19,31 @@ internal class OrderBusinessLogicContract(IOrderStorageContract orderStorageCont private readonly IOrderStorageContract _orderStorageContract = orderStorageContract; public List GetAllOrdersByPeriod(DateTime fromDate, DateTime toDate) { - _logger.LogInformation("GetAllSales params: {fromDate}, {toDate}",fromDate, toDate); - if (fromDate.IsDateNotOlder(toDate)) - { - throw new IncorrectDatesException(fromDate, toDate); - } - return _orderStorageContract.GetList(fromDate, toDate) ?? throw new NullListException(); + return []; } public List GetAllOrdersByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate) { - _logger.LogInformation("GetAllSales 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 _orderStorageContract.GetList(fromDate, toDate, workerId:workerId) ?? throw new NullListException(); + return []; } public List GetAllOrdersByRestaurantByPeriod(string restaurantId, DateTime fromDate, DateTime toDate) { - - _logger.LogInformation("GetAllSales params: {restaurantId}, {fromDate},{ toDate} ", restaurantId, fromDate, toDate); - if (fromDate.IsDateNotOlder(toDate)) - { - throw new IncorrectDatesException(fromDate, toDate); - } - if (restaurantId.IsEmpty()) - { - throw new ArgumentNullException(nameof(restaurantId)); - } - if (!restaurantId.IsGuid()) - { - throw new ValidationException("The value in the field restaurantId is not a unique identifier."); - } - return _orderStorageContract.GetList(fromDate, toDate, restaurantId:restaurantId) ?? throw new NullListException(); + return []; } public List GetAllOrdersByProductByPeriod(string productId, DateTime fromDate, DateTime toDate) { - _logger.LogInformation("GetAllSales params: {productId}, {fromDate},{ toDate}", productId, fromDate, toDate); - if (fromDate.IsDateNotOlder(toDate)) - { - throw new IncorrectDatesException(fromDate, toDate); - } - if (productId.IsEmpty()) - { - throw new ArgumentNullException(nameof(productId)); - } - if (!productId.IsGuid()) - { - throw new ValidationException("The value in the field productId is not a unique identifier."); - } - return _orderStorageContract.GetList(fromDate, toDate, productId: productId) ?? throw new NullListException(); - + return []; } public OrderDataModel GetOrderByData(string data) { - _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 _orderStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data); + return new("", "", "", 0, true, []); } public void InsertOrder(OrderDataModel orderDataModel) { - _logger.LogInformation("New data: {json}",JsonSerializer.Serialize(orderDataModel)); - ArgumentNullException.ThrowIfNull(orderDataModel); - orderDataModel.Validate(); - _orderStorageContract.AddElement(orderDataModel); } public void CancelOrder(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"); - } - _orderStorageContract.DelElement(id); + } } diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/PostBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/PostBusinessLogicContract.cs index 3e25401..c10d736 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/PostBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/PostBusinessLogicContract.cs @@ -16,86 +16,39 @@ namespace PipingHotBusinessLogic.Implementations; internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract { - private readonly ILogger _logger = logger; - private readonly IPostStorageContract _postStorageContract = postStorageContract; public List GetAllPosts(bool onlyActive) { - logger.LogInformation("GetAllPosts params: {onlyActive}",onlyActive); - return _postStorageContract.GetList(onlyActive) ?? throw new NullListException(); + return []; } public List GetAllDataOfPost(string postId) { - _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(); - + return []; } public PostDataModel GetPostByData(string data) { - _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); + + return new("", "", PostType.None, 0, true, DateTime.UtcNow); } 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); + } - + + } diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/ProductBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/ProductBusinessLogicContract.cs index 07022bf..4352567 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/ProductBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/ProductBusinessLogicContract.cs @@ -20,79 +20,32 @@ internal class ProductBusinessLogicContract(IProductStorageContract productStora private readonly IProductStorageContract _productStorageContract = productStorageContract; public List GetAllProducts(bool onlyActive = true) { - _logger.LogInformation("GetAllProducts params: {onlyActive}",onlyActive); - return _productStorageContract.GetList(onlyActive) ?? throw new NullListException(); - + return []; } public List GetAllProductsByRestaurant(string restaurantId, bool onlyActive = true) { - if (restaurantId.IsEmpty()) - { - throw new ArgumentNullException(nameof(restaurantId)); - } - if (!restaurantId.IsGuid()) - { - throw new ValidationException("The value in the field restaurantId is not a unique identifier."); - } - _logger.LogInformation("GetAllProducts params: {restaurantId},{ onlyActive}", restaurantId, onlyActive); - return _productStorageContract.GetList(onlyActive, restaurantId) ?? throw new NullListException(); - + return []; } public List GetProductHistoryByProduct(string productId) { - logger.LogInformation("GetProductHistoryByProduct for {productId}",productId); - if (productId.IsEmpty()) - { - throw new ArgumentNullException(nameof(productId)); - } - if (!productId.IsGuid()) - { - throw new ValidationException("The value in the field productId is not a unique identifier."); - - } - return _productStorageContract.GetHistoryByProductId(productId) ?? throw new NullListException(); - + return []; } public ProductDataModel GetProductByData(string data) { - _logger.LogInformation("Get element by data: {data}", data); - if (data.IsEmpty()) - { - throw new ArgumentNullException(nameof(data)); - } - if (data.IsGuid()) - { - return _productStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data); - } - return _productStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data); + return new("", "", ProductType.None, "", 0, true); } public void InsertProduct(ProductDataModel productDataModel) { - _logger.LogInformation("New data: {json}",JsonSerializer.Serialize(productDataModel)); - ArgumentNullException.ThrowIfNull(productDataModel); - productDataModel.Validate(); - _productStorageContract.AddElement(productDataModel); + } public void UpdateProduct(ProductDataModel productDataModel) { - _logger.LogInformation("Update data: {json}",JsonSerializer.Serialize(productDataModel)); - ArgumentNullException.ThrowIfNull(productDataModel); - productDataModel.Validate(); - _productStorageContract.UpdElement(productDataModel); + } public void DeleteProduct(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"); - } - _productStorageContract.DelElement(id); + } } diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/RestaurantBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/RestaurantBusinessLogicContract.cs index 4f5c7f2..d1518aa 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/RestaurantBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/RestaurantBusinessLogicContract.cs @@ -21,54 +21,25 @@ internal class RestaurantBusinessLogicContract(IRestaurantStorageContract resta public List GetAllRestaurants() { - _logger.LogInformation("GetAllRestaurants"); - return _restaurantStorageContract.GetList() ?? throw new NullListException(); - + return []; } public RestaurantDataModel GetRestaurantByData(string data) { - _logger.LogInformation("Get element by data: {data}", data); - if (data.IsEmpty()) - { - throw new ArgumentNullException(nameof(data)); - } - if (data.IsGuid()) - { - return _restaurantStorageContract.GetElementById(data) ?? - throw new ElementNotFoundException(data); - } - return _restaurantStorageContract.GetElementByName(data) ?? - _restaurantStorageContract.GetElementByOldName(data) ?? - throw new ElementNotFoundException(data); + return new("", "", null, null); } public void InsertRestaurant(RestaurantDataModel restaurantDataModel) { - logger.LogInformation("New data: {json}", JsonSerializer.Serialize(restaurantDataModel)); - ArgumentNullException.ThrowIfNull(restaurantDataModel); - restaurantDataModel.Validate(); - _restaurantStorageContract.AddElement(restaurantDataModel); + } public void UpdateRestaurant(RestaurantDataModel restaurantDataModel) { - _logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(restaurantDataModel)); - ArgumentNullException.ThrowIfNull(restaurantDataModel); - restaurantDataModel.Validate(); - _restaurantStorageContract.UpdElement(restaurantDataModel); + } public void DeleteRestaurant(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"); - } - _restaurantStorageContract.DelElement(id); + } } diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/SalaryBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/SalaryBusinessLogicContract.cs index dfc6a5c..2619fec 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/SalaryBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/SalaryBusinessLogicContract.cs @@ -23,46 +23,15 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC public List 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(); + return []; } public List 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 void CalculateSalaryByMounth(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 orders = _orderStorageContract.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 + orders * 0.1; - _logger.LogDebug("The employee {workerId} was paid a salary of { salary}", worker.Id, salary); - _salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary)); - } } } diff --git a/PipingHot/PipingHotBusinessLogic/Implementations/WorkerBusinessLogicContract.cs b/PipingHot/PipingHotBusinessLogic/Implementations/WorkerBusinessLogicContract.cs index bdc86fb..7bbe30f 100644 --- a/PipingHot/PipingHotBusinessLogic/Implementations/WorkerBusinessLogicContract.cs +++ b/PipingHot/PipingHotBusinessLogic/Implementations/WorkerBusinessLogicContract.cs @@ -21,90 +21,37 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageC public List GetAllWorkers(bool onlyActive = true) { - _logger.LogInformation("GetAllWorkers params: {onlyActive}",onlyActive); - return _workerStorageContract.GetList(onlyActive) ?? throw new NullListException(); + return []; } public List GetAllWorkersByPost(string postId, bool onlyActive = true) { - _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(); - + return []; } public List GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) { - _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(); + return []; } public List GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) { - _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(); + return []; } public WorkerDataModel GetWorkerByData(string data) { - _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); - } - if (Regex.IsMatch(data, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")) - { - return _workerStorageContract.GetElementByEmail(data) ?? - throw new ElementNotFoundException(data); - } - - return _workerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data); - + return new("", "", "", "", DateTime.Now, DateTime.Now, true); } 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); + } }