Browse Source

updated basket appservice with new method

pull/41/head
Galip Tolga Erdem 5 years ago
parent
commit
7ebac77d11
  1. 7
      apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js
  2. 4
      services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IBasketAppService.cs
  3. 23
      services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs
  4. 2
      services/basket/src/EShopOnAbp.BasketService.Domain/BasketServiceDomainModule.cs
  5. 2
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs
  6. 8
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs
  7. 45
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json

7
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',

4
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<BasketDto> GetAsync();
Task<BasketDto> GetByAnonymousUserIdAsync(Guid id);
Task<BasketDto> AddProductAsync(AddProductDto input);
Task<BasketDto> RemoveProductAsync(RemoveProductDto input);
Task PurchaseAsync();

23
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<BasketDto> GetAsync()
{
var basket = await _basketRepository.GetAsync(CurrentUser.GetId());
return await GetBasketDtoAsync(basket);
}
public async Task<BasketDto> GetByAnonymousUserIdAsync(Guid id)
{
var basket = await _basketRepository.GetAsync(id);
return await GetBasketDtoAsync(basket);
}
public async Task<BasketDto> 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;
}
}

2
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)
{

2
services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/BasketServiceHttpApiClientModule.cs

@ -26,4 +26,4 @@ namespace EShopOnAbp.BasketService
});
}
}
}
}

8
services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/BasketClientProxy.Generated.cs

@ -20,6 +20,14 @@ namespace EShopOnAbp.BasketService.ClientProxies
return await RequestAsync<BasketDto>(nameof(GetAsync));
}
public virtual async Task<BasketDto> GetByAnonymousUserIdAsync(Guid id)
{
return await RequestAsync<BasketDto>(nameof(GetByAnonymousUserIdAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), id }
});
}
public virtual async Task<BasketDto> AddProductAsync(AddProductDto input)
{
return await RequestAsync<BasketDto>(nameof(AddProductAsync), new ClientProxyRequestTypeValue

45
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"
}
}

Loading…
Cancel
Save