From 73eb6fffb4db775d05237816b989c1453d0694a9 Mon Sep 17 00:00:00 2001 From: Glliza Date: Sun, 23 Feb 2025 22:33:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IBuyerBusinessLogicContract.cs | 17 +++++ .../IPointsBusinessLogicContract.cs | 15 +++++ .../IPostBusinessLogicContract.cs | 19 ++++++ .../IProductBusinessLogicContract.cs | 18 +++++ .../ISaleBusinessLogicContract.cs | 19 ++++++ .../IWorkerBusinessLogicContract.cs | 20 ++++++ .../DataModels/PostDataModel.cs | 9 +-- .../IBuyerStorageContract.cs | 19 ++++++ .../IPointsStorageContract.cs | 14 ++++ .../StoragesContracts/IPostStorageContract.cs | 20 ++++++ .../IProductStorageContract.cs | 20 ++++++ .../StoragesContracts/ISaleStorageContract.cs | 16 +++++ .../IWorkerStorageContract.cs | 19 ++++++ .../DataModelsTests/PostDataModelTests.cs | 66 +++++-------------- 14 files changed, 233 insertions(+), 58 deletions(-) create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IBuyerBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPointsBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPostBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IProductBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/ISaleBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IWorkerBusinessLogicContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/IBuyerStorageContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/IPointsStorageContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/IPostStorageContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/IProductStorageContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/ISaleStorageContract.cs create mode 100644 PuferFishContracts/PuferFishContracts/StoragesContracts/IWorkerStorageContract.cs diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IBuyerBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IBuyerBusinessLogicContract.cs new file mode 100644 index 0000000..dd7261b --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IBuyerBusinessLogicContract.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface IBuyerBusinessLogicContract +{ + List GetAllBuyers(); + BuyerDataModel GetBuyerByData(string data); + void InsertBuyer(BuyerDataModel buyerDataModel); + void UpdateBuyer(BuyerDataModel buyerDataModel); + void DeleteBuyer(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPointsBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPointsBusinessLogicContract.cs new file mode 100644 index 0000000..be4ab04 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPointsBusinessLogicContract.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface IPointsBusinessLogicContract +{ + List GetAllPointsByPeriod(DateTime fromDate, DateTime toDate); + List GetAllPointsByPeriodByBuyer(DateTime fromDate, DateTime toDate, string buyerId); + void CalculatePointsByMounth(DateTime date); +} diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPostBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPostBusinessLogicContract.cs new file mode 100644 index 0000000..bb2688f --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IPostBusinessLogicContract.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface IPostBusinessLogicContract +{ + List GetAllPosts(bool onlyActive); + List GetAllDataOfPost(string postId); + PostDataModel GetPostByData(string data); + void InsertPost(PostDataModel postDataModel); + void UpdatePost(PostDataModel postDataModel); + void DeletePost(string id); + void RestorePost(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IProductBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IProductBusinessLogicContract.cs new file mode 100644 index 0000000..10a532e --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IProductBusinessLogicContract.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface IProductBusinessLogicContract +{ + List GetAllProducts(bool onlyActive = true); + List GetProductHistoryByProduct(string productId); + ProductDataModel GetProductByData(string data); + void InsertProduct(ProductDataModel productDataModel); + void UpdateProduct(ProductDataModel productDataModel); + void DeleteProduct(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/ISaleBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/ISaleBusinessLogicContract.cs new file mode 100644 index 0000000..6ea22ad --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/ISaleBusinessLogicContract.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface ISaleBusinessLogicContract +{ + List GetAllSalesByPeriod(DateTime fromDate, DateTime toDate); + List GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate); + List GetAllSalesByBuyerByPeriod(string buyerId, DateTime fromDate, DateTime toDate); + List GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate); + SaleDataModel GetSaleByData(string data); + void InsertSale(SaleDataModel saleDataModel); + void CancelSale(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IWorkerBusinessLogicContract.cs b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IWorkerBusinessLogicContract.cs new file mode 100644 index 0000000..20bfd6a --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/BusinessLogicsContracts/IWorkerBusinessLogicContract.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.BusinessLogicsContracts; + +public interface IWorkerBusinessLogicContract +{ + List GetAllWorkers(bool onlyActive = true); + List GetAllWorkersByPost(string postId, bool onlyActive = true); + List GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true); + List GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true); + WorkerDataModel GetWorkerByData(string data); + void InsertWorker(WorkerDataModel workerDataModel); + void UpdateWorker(WorkerDataModel workerDataModel); + void DeleteWorker(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/DataModels/PostDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/PostDataModel.cs index dfd74d8..d9bfea5 100644 --- a/PuferFishContracts/PuferFishContracts/DataModels/PostDataModel.cs +++ b/PuferFishContracts/PuferFishContracts/DataModels/PostDataModel.cs @@ -11,10 +11,9 @@ using System.Xml; namespace PuferFishContracts.DataModels { - public class PostDataModel(string id, string postId, string postName, PostType postType, bool isActual, DateTime changeDate) : IValidation + public class PostDataModel(string id, string postName, PostType postType, bool isActual, DateTime changeDate) : IValidation { public string Id { get; private set; } = id; - public string PostId { get; private set; } = postId; public string PostName { get; private set; } = postName; public PostType PostType { get; private set; } = postType; public bool IsActual { get; private set; } = isActual; @@ -25,11 +24,7 @@ namespace PuferFishContracts.DataModels throw new ValidationException("Field Id is empty"); if (!Id.IsGuid()) throw new ValidationException("The value in the field Id is not a unique identifier"); - if (PostId.IsEmpty()) - throw new ValidationException("Field PostId is empty"); - if (!PostId.IsGuid()) - throw new ValidationException("The value in the field PostId is not a unique identifier"); - if (PostName.IsEmpty()) + if (PostName.IsEmpty()) throw new ValidationException("Field PostName is empty"); if (PostType == PostType.None) throw new ValidationException("Field PostType is empty"); diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/IBuyerStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/IBuyerStorageContract.cs new file mode 100644 index 0000000..df1e529 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/IBuyerStorageContract.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface IBuyerStorageContract +{ + List GetList(); + BuyerDataModel? GetElementById(string id); + BuyerDataModel? GetElementByPhoneNumber(string phoneNumber); + BuyerDataModel? GetElementByFIO(string fio); + void AddElement(BuyerDataModel buyerDataModel); + void UpdElement(BuyerDataModel buyerDataModel); + void DelElement(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/IPointsStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/IPointsStorageContract.cs new file mode 100644 index 0000000..0802be5 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/IPointsStorageContract.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface IPointsStorageContract +{ + List GetList(DateTime startDate, DateTime endDate, string? buyerId = null); + void AddElement(PointsDataModel pointsDataModel); +} diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/IPostStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/IPostStorageContract.cs new file mode 100644 index 0000000..75af3bb --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/IPostStorageContract.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface IPostStorageContract +{ + List GetList(bool onlyActual = true); + List GetPostWithHistory(string postId); + PostDataModel? GetElementById(string id); + PostDataModel? GetElementByName(string name); + void AddElement(PostDataModel postDataModel); + void UpdElement(PostDataModel postDataModel); + void DelElement(string id); + void ResElement(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/IProductStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/IProductStorageContract.cs new file mode 100644 index 0000000..86c4773 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/IProductStorageContract.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface IProductStorageContract +{ + List GetList(bool onlyActive = true, string? +manufacturerId = null); + List GetHistoryByProductId(string productId); + ProductDataModel? GetElementById(string id); + ProductDataModel? GetElementByName(string name); + void AddElement(ProductDataModel productDataModel); + void UpdElement(ProductDataModel productDataModel); + void DelElement(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/ISaleStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/ISaleStorageContract.cs new file mode 100644 index 0000000..7564b9f --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/ISaleStorageContract.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface ISaleStorageContract +{ + List GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? buyerId = null, string? productId = null); + SaleDataModel? GetElementById(string id); + void AddElement(SaleDataModel saleDataModel); + void DelElement(string id); +} diff --git a/PuferFishContracts/PuferFishContracts/StoragesContracts/IWorkerStorageContract.cs b/PuferFishContracts/PuferFishContracts/StoragesContracts/IWorkerStorageContract.cs new file mode 100644 index 0000000..05f898a --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/StoragesContracts/IWorkerStorageContract.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; + +namespace PuferFishContracts.StoragesContracts; + +public interface IWorkerStorageContract +{ + List GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? +fromEmploymentDate = null, DateTime? toEmploymentDate = null); + WorkerDataModel? GetElementById(string id); + WorkerDataModel? GetElementByFIO(string fio); + void AddElement(WorkerDataModel workerDataModel); + void UpdElement(WorkerDataModel workerDataModel); + void DelElement(string id); +} diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/PostDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/PostDataModelTests.cs index b946281..222d853 100644 --- a/PuferFishContracts/PuferFishTests/DataModelsTests/PostDataModelTests.cs +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/PostDataModelTests.cs @@ -15,98 +15,62 @@ internal class PostDataModelTests [Test] public void IdIsNullOrEmptyTest() { - var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", - PostType.Cashier, true, DateTime.UtcNow); + var post = CreateDataModel(null, "name", PostType.chef, + true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), - "name", PostType.Cashier, true, DateTime.UtcNow); + post = CreateDataModel(string.Empty, "name", PostType.chef, + true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { - var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", - PostType.Cashier, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), - Throws.TypeOf()); - } - [Test] - public void PostIdIsNullEmptyTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", - PostType.Cashier, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), - Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, - "name", PostType.Cashier, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), - Throws.TypeOf()); - } - [Test] - public void PostIdIsNotGuidTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", - "name", PostType.Cashier, true, DateTime.UtcNow); + var post = CreateDataModel("id", "name", PostType.chef, + true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void PostNameIsEmptyTest() { - var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), - Guid.NewGuid().ToString(), null, PostType.Cashier, true, DateTime.UtcNow); + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.chef, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); manufacturer = CreateDataModel(Guid.NewGuid().ToString(), - Guid.NewGuid().ToString(), string.Empty, PostType.Cashier, true, - DateTime.UtcNow); + string.Empty, PostType.chef, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); } [Test] public void PostTypeIsNoneTest() { - var post = CreateDataModel(Guid.NewGuid().ToString(), - Guid.NewGuid().ToString(), "name", PostType.None, true, DateTime.UtcNow); + var post = CreateDataModel(Guid.NewGuid().ToString(), "name", + PostType.None, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } - /*[Test] - public void SalaryIsLessOrZeroTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), - Guid.NewGuid().ToString(), "name", PostType.Cashier, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), - Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, true,DateTime.UtcNow); - Assert.That(() => post.Validate(), - Throws.TypeOf()); - }*/ [Test] public void AllFieldsIsCorrectTest() { var postId = Guid.NewGuid().ToString(); - var postPostId = Guid.NewGuid().ToString(); var postName = "name"; - var postType = PostType.Cashier; - var salary = 10; + var postType = PostType.chef; var isActual = false; var changeDate = DateTime.UtcNow.AddDays(-1); - var post = CreateDataModel(postId, postPostId, postName, postType, isActual, changeDate); + var post = CreateDataModel(postId, postName, postType, + isActual, changeDate); Assert.That(() => post.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(post.Id, Is.EqualTo(postId)); - Assert.That(post.PostId, Is.EqualTo(postPostId)); Assert.That(post.PostName, Is.EqualTo(postName)); Assert.That(post.PostType, Is.EqualTo(postType)); - //Assert.That(post.Salary, Is.EqualTo(salary)); Assert.That(post.IsActual, Is.EqualTo(isActual)); Assert.That(post.ChangeDate, Is.EqualTo(changeDate)); }); } - private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, bool isActual, DateTime changeDate) => new (id, postId, postName, postType, isActual, changeDate); -} + private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, bool isActual, DateTime changeDate) => new(id, postName, postType, isActual, changeDate); +} \ No newline at end of file