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
parent
commit
a719763dbd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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 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");

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

@ -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));
};

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

@ -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; }
}

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;
public class RemoveProductDto
public class RemoveProductDto : IHasAnonymousId
{
public Guid ProductId { 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)
{
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);

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

@ -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": {

Loading…
Cancel
Save