Browse Source
Merge pull request #42 from abpframework/gterdem/catalog_update_anonymous_id
Add AnonymousId to DTOs
pull/43/head
Galip Tolga Erdem
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
36 additions and
6 deletions
-
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js
-
apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js
-
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs
-
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs
-
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs
-
services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs
-
services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json
|
|
|
@ -15,7 +15,8 @@ |
|
|
|
var $this = $(this); |
|
|
|
var productId = $this.attr('data-product-id'); |
|
|
|
eShopOnAbp.basketService.basket.addProduct({ |
|
|
|
productId: productId |
|
|
|
productId: productId, |
|
|
|
anonymousId: anonymousId, |
|
|
|
}).then(function () { |
|
|
|
widgetManager.refresh(); |
|
|
|
abp.notify.success("Added product to your basket.", "Successfully added"); |
|
|
|
|
|
|
|
@ -35,7 +35,7 @@ |
|
|
|
|
|
|
|
eShopOnAbp.basketService.basket.removeProduct = function(input, ajaxParams) { |
|
|
|
return abp.ajax($.extend(true, { |
|
|
|
url: abp.appPath + 'api/basket/basket/product' + abp.utils.buildQueryString([{ name: 'productId', value: input.productId }, { name: 'count', value: input.count }]) + '', |
|
|
|
url: abp.appPath + 'api/basket/basket/product' + abp.utils.buildQueryString([{ name: 'productId', value: input.productId }, { name: 'count', value: input.count }, { name: 'anonymousId', value: input.anonymousId }]) + '', |
|
|
|
type: 'DELETE' |
|
|
|
}, ajaxParams)); |
|
|
|
}; |
|
|
|
|
|
|
|
@ -3,10 +3,12 @@ using System.ComponentModel.DataAnnotations; |
|
|
|
|
|
|
|
namespace EShopOnAbp.BasketService; |
|
|
|
|
|
|
|
public class AddProductDto |
|
|
|
public class AddProductDto : IHasAnonymousId |
|
|
|
{ |
|
|
|
public Guid ProductId { get; set; } |
|
|
|
|
|
|
|
[Range(1, int.MaxValue)] |
|
|
|
public int Count { get; set; } = 1; |
|
|
|
|
|
|
|
public Guid? AnonymousId { get; set; } |
|
|
|
} |
|
|
|
@ -0,0 +1,9 @@ |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace EShopOnAbp.BasketService |
|
|
|
{ |
|
|
|
public interface IHasAnonymousId |
|
|
|
{ |
|
|
|
Guid? AnonymousId { get; } |
|
|
|
} |
|
|
|
} |
|
|
|
@ -2,9 +2,11 @@ using System; |
|
|
|
|
|
|
|
namespace EShopOnAbp.BasketService; |
|
|
|
|
|
|
|
public class RemoveProductDto |
|
|
|
public class RemoveProductDto : IHasAnonymousId |
|
|
|
{ |
|
|
|
public Guid ProductId { get; set; } |
|
|
|
|
|
|
|
public int? Count { get; set; } |
|
|
|
|
|
|
|
public Guid? AnonymousId { get; set; } |
|
|
|
} |
|
|
|
@ -42,7 +42,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService |
|
|
|
|
|
|
|
public async Task<BasketDto> AddProductAsync(AddProductDto input) |
|
|
|
{ |
|
|
|
Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : _anonymousUserId; |
|
|
|
Console.WriteLine("========================= AnonymousId: "+input.AnonymousId); |
|
|
|
|
|
|
|
Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : input.AnonymousId.GetValueOrDefault(); |
|
|
|
|
|
|
|
var basket = await _basketRepository.GetAsync(userId); |
|
|
|
var product = await _basketProductService.GetAsync(input.ProductId); |
|
|
|
@ -61,7 +63,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService |
|
|
|
|
|
|
|
public async Task<BasketDto> RemoveProductAsync(RemoveProductDto input) |
|
|
|
{ |
|
|
|
var basket = await _basketRepository.GetAsync(CurrentUser.GetId()); |
|
|
|
Guid userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : input.AnonymousId.GetValueOrDefault(); |
|
|
|
|
|
|
|
var basket = await _basketRepository.GetAsync(userId); |
|
|
|
var product = await _basketProductService.GetAsync(input.ProductId); |
|
|
|
|
|
|
|
basket.RemoveProduct(product.Id, input.Count); |
|
|
|
|
|
|
|
@ -152,6 +152,18 @@ |
|
|
|
"constraintTypes": null, |
|
|
|
"bindingSourceId": "ModelBinding", |
|
|
|
"descriptorName": "input" |
|
|
|
}, |
|
|
|
{ |
|
|
|
"nameOnMethod": "input", |
|
|
|
"name": "AnonymousId", |
|
|
|
"jsonName": null, |
|
|
|
"type": "System.Guid?", |
|
|
|
"typeSimple": "string?", |
|
|
|
"isOptional": false, |
|
|
|
"defaultValue": null, |
|
|
|
"constraintTypes": null, |
|
|
|
"bindingSourceId": "ModelBinding", |
|
|
|
"descriptorName": "input" |
|
|
|
} |
|
|
|
], |
|
|
|
"returnValue": { |
|
|
|
|