From 382812c8f448e200cd924b3bd22640253886e3e6 Mon Sep 17 00:00:00 2001 From: NotTastyCupcake Date: Fri, 5 Aug 2022 14:36:10 +0500 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BasketAggregate/Basket.cs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs b/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs index d92f73a..058292d 100644 --- a/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs +++ b/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs @@ -3,20 +3,38 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate; -public class Basket : BaseEntity +public class Basket { - private readonly ICollection _items; + public int Id { get; set; } + public List Items { get; private set; } + + public int TotalItems => Items.Sum(i => i.Quantity); + public Basket() { - _items = new List(); + Items = new List(); } public void AddItem(int catalogItemId, decimal amountPrice, int quantity = 1) { - var basket = new BasketItem(catalogItemId,amountPrice,quantity); - if(_items.Any(i => i.CatalogItemId == catalogItemId)) + if(Items.Any(i => i.CatalogItemId == catalogItemId)) + { + var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); + existingItem.AddQuantity(quantity); + } + else { - + var newBasketItem = new BasketItem(catalogItemId,amountPrice,quantity); + Items.Add(newBasketItem); } } + public void DeleteItem(int catalogItemId) + { + var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); + existingItem.DeleteQuantity(); + } + public void RemoveEmptyItems() + { + Items.RemoveAll(i => i.Quantity == 0); + } } \ No newline at end of file From 884437c43abecb5d35ec8f94a914392ec81f9947 Mon Sep 17 00:00:00 2001 From: NotTastyCupcake Date: Fri, 5 Aug 2022 14:37:42 +0500 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20BaseEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/ApplicationCore/Entities/BaseEntity.cs | 6 ------ .../Entities/BasketAggregate/BasketItem.cs | 13 ++++++++++++- Src/ApplicationCore/Entities/CatalogItem.cs | 6 +++--- Src/ApplicationCore/Entities/CatalogType.cs | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) delete mode 100644 Src/ApplicationCore/Entities/BaseEntity.cs diff --git a/Src/ApplicationCore/Entities/BaseEntity.cs b/Src/ApplicationCore/Entities/BaseEntity.cs deleted file mode 100644 index c3d8aec..0000000 --- a/Src/ApplicationCore/Entities/BaseEntity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace ProgGym.CoffeeShop.ApplicationCore.Entities; - -public abstract class BaseEntity -{ - public virtual int Id { get; set; } -} \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs index 7e9fe7c..34dc3cf 100644 --- a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs +++ b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs @@ -1,7 +1,8 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate; -public class BasketItem : BaseEntity +public class BasketItem { + public int Id { get; set; } public decimal AmountPrice { get; private set; } public int Quantity { get; private set; } public int CatalogItemId { get; private set; } @@ -12,4 +13,14 @@ public BasketItem(int catalogItemId, decimal amountPrice, int quantity) Quantity = quantity; } + public void AddQuantity(int quantity) + { + Quantity += quantity; + } + + public void DeleteQuantity() + { + Quantity -= 1; + } + } \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/CatalogItem.cs b/Src/ApplicationCore/Entities/CatalogItem.cs index 531b216..9021ddb 100644 --- a/Src/ApplicationCore/Entities/CatalogItem.cs +++ b/Src/ApplicationCore/Entities/CatalogItem.cs @@ -1,7 +1,8 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities; -public class CatalogItem : BaseEntity +public class CatalogItem { + public int Id { get; set; } public string Name { get; private set; } public string Description { get; private set; } public decimal Price { get; private set; } @@ -9,9 +10,8 @@ public class CatalogItem : BaseEntity public int CatalogTypeId { get; private set; } public CatalogType CatalogType { get; private set; } - public CatalogItem(int id,string name, string description, decimal price,string pictureUri, int catalogItemId) + public CatalogItem(string name, string description, decimal price,string pictureUri, int catalogItemId) { - Id = id; Name = name; Description = description; Price = price; diff --git a/Src/ApplicationCore/Entities/CatalogType.cs b/Src/ApplicationCore/Entities/CatalogType.cs index 0aab9ec..aca783a 100644 --- a/Src/ApplicationCore/Entities/CatalogType.cs +++ b/Src/ApplicationCore/Entities/CatalogType.cs @@ -1,7 +1,8 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities; -public class CatalogType : BaseEntity +public class CatalogType { + public int Id { get; set; } public string Type { get; private set; } public CatalogType(string type) { From ead9f0a386019dd7f9b3eb069accde1ba373ce79 Mon Sep 17 00:00:00 2001 From: NotTastyCupcake Date: Fri, 5 Aug 2022 14:39:07 +0500 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=20=D0=B4=D0=BB=D1=8F=20=D0=9B=D0=BE=D0=B3=D0=B5=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/ApplicationCore/Interfaces/IAppLogger.cs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Src/ApplicationCore/Interfaces/IAppLogger.cs diff --git a/Src/ApplicationCore/Interfaces/IAppLogger.cs b/Src/ApplicationCore/Interfaces/IAppLogger.cs new file mode 100644 index 0000000..44d7382 --- /dev/null +++ b/Src/ApplicationCore/Interfaces/IAppLogger.cs @@ -0,0 +1,7 @@ +namespace ProgGym.CoffeeShop.ApplicationCore.Interfaces; +interface IAppLogger +{ + void LogInformation(string messange, params object[] args); + void LogWarning(string messange, params object[] args); + void LogError(string messange, params object[] args); +} \ No newline at end of file From 7fea85af23f7c58a56ca5b2494be562bf732d594 Mon Sep 17 00:00:00 2001 From: NotTastyCupcake Date: Fri, 5 Aug 2022 14:39:45 +0500 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/ApplicationCore/ApplicationCore.csproj | 4 ++++ Src/ApplicationCore/Interfaces/IRepository.cs | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 Src/ApplicationCore/Interfaces/IRepository.cs diff --git a/Src/ApplicationCore/ApplicationCore.csproj b/Src/ApplicationCore/ApplicationCore.csproj index 8d9f427..0de61d9 100644 --- a/Src/ApplicationCore/ApplicationCore.csproj +++ b/Src/ApplicationCore/ApplicationCore.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Src/ApplicationCore/Interfaces/IRepository.cs b/Src/ApplicationCore/Interfaces/IRepository.cs new file mode 100644 index 0000000..03aed4e --- /dev/null +++ b/Src/ApplicationCore/Interfaces/IRepository.cs @@ -0,0 +1,8 @@ +using Ardalis.Specification; + +namespace ProgGym.CoffeeShop.ApplicationCore.Interfaces; + +interface IRepository : IRepositoryBase where T : class +{ + +} \ No newline at end of file From a4d344c47a678a4f6323098f93ef26821bde50d0 Mon Sep 17 00:00:00 2001 From: NotTastyCupcake Date: Fri, 5 Aug 2022 14:56:11 +0500 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B4=D0=B8=D0=B0=D0=B3=D1=80=D0=B0=D0=BC=D0=BC?= =?UTF-8?q?=D1=83=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BasketAggregate/BasketItem.cs | 2 + .../Entities/CatalogClassDiagram.cd | 37 +++++++++++++++++++ Src/ApplicationCore/Entities/CatalogItem.cs | 1 + 3 files changed, 40 insertions(+) create mode 100644 Src/ApplicationCore/Entities/CatalogClassDiagram.cd diff --git a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs index 34dc3cf..7c2ea7d 100644 --- a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs +++ b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs @@ -6,6 +6,8 @@ public class BasketItem public decimal AmountPrice { get; private set; } public int Quantity { get; private set; } public int CatalogItemId { get; private set; } + public CatalogItem CatalogItem { get; private set; } + public BasketItem(int catalogItemId, decimal amountPrice, int quantity) { CatalogItemId = catalogItemId; diff --git a/Src/ApplicationCore/Entities/CatalogClassDiagram.cd b/Src/ApplicationCore/Entities/CatalogClassDiagram.cd new file mode 100644 index 0000000..d3acfbc --- /dev/null +++ b/Src/ApplicationCore/Entities/CatalogClassDiagram.cd @@ -0,0 +1,37 @@ + + + + + + + + AAACAAAAAwAgAgAAAAAAAAQAAAAAAAAAAAAAAAAACAA= + Entities\CatalogItem.cs + + + + + + + + + + + AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA= + Entities\CatalogType.cs + + + + + + AAICAAAAAKAAEAAAAAgAAAAAAAAAAAAAAAAAgAAAAAA= + Entities\BasketAggregate\BasketItem.cs + + + + + + + \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/CatalogItem.cs b/Src/ApplicationCore/Entities/CatalogItem.cs index 9021ddb..f9c9569 100644 --- a/Src/ApplicationCore/Entities/CatalogItem.cs +++ b/Src/ApplicationCore/Entities/CatalogItem.cs @@ -10,6 +10,7 @@ public class CatalogItem public int CatalogTypeId { get; private set; } public CatalogType CatalogType { get; private set; } + public CatalogItem(string name, string description, decimal price,string pictureUri, int catalogItemId) { Name = name;