From 7ebac77d11f6da67129960fdd971360416a37454 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 21 Dec 2021 15:20:06 +0300 Subject: [PATCH] updated basket appservice with new method --- .../wwwroot/client-proxies/basket-proxy.js | 7 +++ .../IBasketAppService.cs | 4 +- .../BasketAppService.cs | 23 ++++++---- .../BasketServiceDomainModule.cs | 2 +- .../BasketServiceHttpApiClientModule.cs | 2 +- .../BasketClientProxy.Generated.cs | 8 ++++ .../ClientProxies/basket-generate-proxy.json | 45 +++++++++++++++++-- 7 files changed, 75 insertions(+), 16 deletions(-) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js index c3877617..ec6cf88e 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js @@ -18,6 +18,13 @@ }, ajaxParams)); }; + eShopOnAbp.basketService.basket.getByAnonymousUserId = function(id, ajaxParams) { + return abp.ajax($.extend(true, { + url: abp.appPath + 'api/basket/basket/' + id + '/by-anonymous-user-id', + type: 'GET' + }, ajaxParams)); + }; + eShopOnAbp.basketService.basket.addProduct = function(input, ajaxParams) { return abp.ajax($.extend(true, { url: abp.appPath + 'api/basket/basket/product', diff --git a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IBasketAppService.cs b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IBasketAppService.cs index 00266aa7..55a4ba0a 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IBasketAppService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IBasketAppService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Volo.Abp.Application.Services; namespace EShopOnAbp.BasketService; @@ -6,6 +7,7 @@ namespace EShopOnAbp.BasketService; public interface IBasketAppService : IApplicationService { Task GetAsync(); + Task GetByAnonymousUserIdAsync(Guid id); Task AddProductAsync(AddProductDto input); Task RemoveProductAsync(RemoveProductDto input); Task PurchaseAsync(); diff --git a/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs b/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs index 76d77784..c7e06212 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs @@ -10,7 +10,6 @@ using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.BasketService; -[Authorize] public class BasketAppService : BasketServiceAppService, IBasketAppService { private readonly IBasketRepository _basketRepository; @@ -26,13 +25,19 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService _basketProductService = basketProductService; _distributedEventBus = distributedEventBus; } - + public async Task GetAsync() { var basket = await _basketRepository.GetAsync(CurrentUser.GetId()); return await GetBasketDtoAsync(basket); } + public async Task GetByAnonymousUserIdAsync(Guid id) + { + var basket = await _basketRepository.GetAsync(id); + return await GetBasketDtoAsync(basket); + } + public async Task AddProductAsync(AddProductDto input) { var basket = await _basketRepository.GetAsync(CurrentUser.GetId()); @@ -42,11 +47,11 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService { throw new UserFriendlyException("There is not enough product in stock, sorry :("); } - + basket.AddProduct(product.Id); await _basketRepository.UpdateAsync(basket); - + return await GetBasketDtoAsync(basket); } @@ -54,11 +59,11 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService { var basket = await _basketRepository.GetAsync(CurrentUser.GetId()); var product = await _basketProductService.GetAsync(input.ProductId); - + basket.RemoveProduct(product.Id, input.Count); - + await _basketRepository.UpdateAsync(basket); - + return await GetBasketDtoAsync(basket); } @@ -85,7 +90,7 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService productDto = await _basketProductService.GetAsync(basketItem.ProductId); products[productDto.Id] = productDto; } - + //Removing the products if not available in the stock if (basketItem.Count > productDto.StockCount) { @@ -110,7 +115,7 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService { await _basketRepository.UpdateAsync(basket); } - + return basketDto; } } \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.Domain/BasketServiceDomainModule.cs b/services/basket/src/EShopOnAbp.BasketService.Domain/BasketServiceDomainModule.cs index e3992597..39230157 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Domain/BasketServiceDomainModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Domain/BasketServiceDomainModule.cs @@ -11,7 +11,7 @@ namespace EShopOnAbp.BasketService typeof(AbpDddDomainModule), typeof(AbpCachingModule) )] - public class BasketServiceDomainModule : AbpModule + public class BasketServiceDomainModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs index 36b13872..093c7352 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs @@ -26,4 +26,4 @@ namespace EShopOnAbp.BasketService }); } } -} +} \ No newline at end of file diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs index 014328ed..6a723592 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs @@ -20,6 +20,14 @@ namespace EShopOnAbp.BasketService.ClientProxies return await RequestAsync(nameof(GetAsync)); } + public virtual async Task GetByAnonymousUserIdAsync(Guid id) + { + return await RequestAsync(nameof(GetByAnonymousUserIdAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), id } + }); + } + public virtual async Task AddProductAsync(AddProductDto input) { return await RequestAsync(nameof(AddProductAsync), new ClientProxyRequestTypeValue diff --git a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json index c6f742a4..0ff4ec2a 100644 --- a/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json +++ b/services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json @@ -35,7 +35,44 @@ "type": "EShopOnAbp.BasketService.BasketDto", "typeSimple": "EShopOnAbp.BasketService.BasketDto" }, - "allowAnonymous": false, + "allowAnonymous": null, + "implementFrom": "EShopOnAbp.BasketService.IBasketAppService" + }, + "GetByAnonymousUserIdAsyncById": { + "uniqueName": "GetByAnonymousUserIdAsyncById", + "name": "GetByAnonymousUserIdAsync", + "httpMethod": "GET", + "url": "api/basket/basket/{id}/by-anonymous-user-id", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "id", + "name": "id", + "jsonName": null, + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "EShopOnAbp.BasketService.BasketDto", + "typeSimple": "EShopOnAbp.BasketService.BasketDto" + }, + "allowAnonymous": null, "implementFrom": "EShopOnAbp.BasketService.IBasketAppService" }, "AddProductAsyncByInput": { @@ -72,7 +109,7 @@ "type": "EShopOnAbp.BasketService.BasketDto", "typeSimple": "EShopOnAbp.BasketService.BasketDto" }, - "allowAnonymous": false, + "allowAnonymous": null, "implementFrom": "EShopOnAbp.BasketService.IBasketAppService" }, "RemoveProductAsyncByInput": { @@ -121,7 +158,7 @@ "type": "EShopOnAbp.BasketService.BasketDto", "typeSimple": "EShopOnAbp.BasketService.BasketDto" }, - "allowAnonymous": false, + "allowAnonymous": null, "implementFrom": "EShopOnAbp.BasketService.IBasketAppService" }, "PurchaseAsync": { @@ -136,7 +173,7 @@ "type": "System.Void", "typeSimple": "System.Void" }, - "allowAnonymous": false, + "allowAnonymous": null, "implementFrom": "EShopOnAbp.BasketService.IBasketAppService" } }