Browse Source

Add anonymousid to DTOs

pull/42/head
enisn 5 years ago
parent
commit
7d9fb038be
  1. 3
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js
  2. 2
      apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js
  3. 4
      services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs
  4. 9
      services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs
  5. 4
      services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs
  6. 8
      services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs
  7. 12
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json

3
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/index.js

@ -15,7 +15,8 @@
var $this = $(this); var $this = $(this);
var productId = $this.attr('data-product-id'); var productId = $this.attr('data-product-id');
eShopOnAbp.basketService.basket.addProduct({ eShopOnAbp.basketService.basket.addProduct({
productId: productId productId: productId,
anonymousId: anonymousId,
}).then(function () { }).then(function () {
widgetManager.refresh(); widgetManager.refresh();
abp.notify.success("Added product to your basket.", "Successfully added"); abp.notify.success("Added product to your basket.", "Successfully added");

2
apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/client-proxies/basket-proxy.js

@ -35,7 +35,7 @@
eShopOnAbp.basketService.basket.removeProduct = function(input, ajaxParams) { eShopOnAbp.basketService.basket.removeProduct = function(input, ajaxParams) {
return abp.ajax($.extend(true, { 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' type: 'DELETE'
}, ajaxParams)); }, ajaxParams));
}; };

4
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/AddProductDto.cs

@ -3,10 +3,12 @@ using System.ComponentModel.DataAnnotations;
namespace EShopOnAbp.BasketService; namespace EShopOnAbp.BasketService;
public class AddProductDto public class AddProductDto : IHasAnonymousId
{ {
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
[Range(1, int.MaxValue)] [Range(1, int.MaxValue)]
public int Count { get; set; } = 1; public int Count { get; set; } = 1;
public Guid? AnonymousId { get; set; }
} }

9
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/IHasAnonymousId.cs

@ -0,0 +1,9 @@
using System;
namespace EShopOnAbp.BasketService
{
public interface IHasAnonymousId
{
Guid? AnonymousId { get; }
}
}

4
services/basket/src/EShopOnAbp.BasketService.Application.Contracts/RemoveProductDto.cs

@ -2,9 +2,11 @@ using System;
namespace EShopOnAbp.BasketService; namespace EShopOnAbp.BasketService;
public class RemoveProductDto public class RemoveProductDto : IHasAnonymousId
{ {
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
public int? Count { get; set; } public int? Count { get; set; }
public Guid? AnonymousId { get; set; }
} }

8
services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs

@ -42,7 +42,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService
public async Task<BasketDto> AddProductAsync(AddProductDto input) 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 basket = await _basketRepository.GetAsync(userId);
var product = await _basketProductService.GetAsync(input.ProductId); var product = await _basketProductService.GetAsync(input.ProductId);
@ -61,7 +63,9 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService
public async Task<BasketDto> RemoveProductAsync(RemoveProductDto input) 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); var product = await _basketProductService.GetAsync(input.ProductId);
basket.RemoveProduct(product.Id, input.Count); basket.RemoveProduct(product.Id, input.Count);

12
services/basket/src/EShopOnAbp.BasketService.HttpApi.Client/ClientProxies/basket-generate-proxy.json

@ -152,6 +152,18 @@
"constraintTypes": null, "constraintTypes": null,
"bindingSourceId": "ModelBinding", "bindingSourceId": "ModelBinding",
"descriptorName": "input" "descriptorName": "input"
},
{
"nameOnMethod": "input",
"name": "AnonymousId",
"jsonName": null,
"type": "System.Guid?",
"typeSimple": "string?",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "ModelBinding",
"descriptorName": "input"
} }
], ],
"returnValue": { "returnValue": {

Loading…
Cancel
Save