Browse Source

Initial "add to basket"

pull/37/head
Halil İbrahim Kalkan 5 years ago
parent
commit
7d25d88e77
  1. 17
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
  2. 4
      services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs
  3. 8
      services/basket/src/EShopOnAbp.BasketService.Application/BasketAppService.cs
  4. 4
      services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs
  5. 2
      services/basket/src/EShopOnAbp.BasketService.Domain/Basket.cs
  6. 1
      services/basket/src/EShopOnAbp.BasketService.Domain/BasketRepository.cs
  7. 12
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs
  8. 4
      services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json
  9. 4
      services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/Products/IPublicProductAppService.cs
  10. 6
      services/catalog/src/EShopOnAbp.CatalogService.Application/Products/PublicProductAppService.cs
  11. 8
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Client/ClientProxies/PublicProductClientProxy.Generated.cs
  12. 37
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Client/ClientProxies/catalog-generate-proxy.json
  13. 2
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs
  14. 2
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json

17
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs

@ -1,11 +1,14 @@
using System;
using System.Net.Http.Headers;
using EShopOnAbp.BasketService;
using EShopOnAbp.CatalogService;
using EShopOnAbp.Localization;
using EShopOnAbp.PublicWeb.Menus;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
@ -26,6 +29,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Yarp.ReverseProxy.Transforms;
namespace EShopOnAbp.PublicWeb
{
@ -124,7 +128,18 @@ namespace EShopOnAbp.PublicWeb
context.Services
.AddReverseProxy()
.LoadFromConfig(configuration.GetSection("ReverseProxy"));
.LoadFromConfig(configuration.GetSection("ReverseProxy"))
.AddTransforms(builderContext =>
{
builderContext.AddRequestTransform(async (transformContext) =>
{
transformContext.ProxyRequest.Headers
.Authorization = new AuthenticationHeaderValue(
"Bearer",
await transformContext.HttpContext.GetTokenAsync("access_token")
);
});
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

4
services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs

@ -85,6 +85,10 @@ namespace EShopOnAbp.AdministrationService
//app.UseHttpMetrics();
app.UseAuthentication();
app.UseAbpClaimsMap();
app.Use(async (httpContext, func) =>
{
await func();
});
app.UseAuthorization();
app.UseSwagger();
app.UseSwaggerUI(options =>

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

@ -34,6 +34,10 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService
var product = await _basketProductService.GetAsync(input.ProductId);
basket.AddProduct(product.Id);
await _basketRepository.UpdateAsync(basket);
var basket2 = await _basketRepository.GetAsync(CurrentUser.GetId());
return await GetBasketDtoAsync(basket);
}
@ -45,6 +49,8 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService
basket.RemoveProduct(product.Id, input.Count);
await _basketRepository.UpdateAsync(basket);
return await GetBasketDtoAsync(basket);
}
@ -73,6 +79,8 @@ public class BasketAppService : BasketServiceAppService, IBasketAppService
basketItemDto.ImageName = productDto.ImageName;
basketItemDto.ProductName = productDto.Name;
basketItemDto.TotalPrice = productDto.Price * basketItemDto.Count;
basketDto.Items.Add(basketItemDto);
}
basketDto.TotalPrice = basketDto.Items.Sum(x => x.TotalPrice);

4
services/basket/src/EShopOnAbp.BasketService.Application/BasketProductService.cs

@ -9,11 +9,11 @@ namespace EShopOnAbp.BasketService;
public class BasketProductService : IBasketProductService, ITransientDependency
{
private readonly IProductAppService _productAppService;
private readonly IPublicProductAppService _productAppService;
private readonly IDistributedCache<ProductDto, Guid> _cache;
public BasketProductService(
IProductAppService productAppService,
IPublicProductAppService productAppService,
IDistributedCache<ProductDto, Guid> cache)
{
_productAppService = productAppService;

2
services/basket/src/EShopOnAbp.BasketService.Domain/Basket.cs

@ -7,7 +7,7 @@ namespace EShopOnAbp.BasketService;
public class Basket : AggregateRoot<Guid>
{
public List<BasketItem> Items { get; private set; }
public List<BasketItem> Items { get; set; }
private Basket()
{

1
services/basket/src/EShopOnAbp.BasketService.Domain/BasketRepository.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Caching;

12
services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/BasketServiceHttpApiHostModule.cs

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
using Volo.Abp.Modularity;
namespace EShopOnAbp.BasketService
@ -27,7 +28,7 @@ namespace EShopOnAbp.BasketService
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
JwtBearerConfigurationHelper.Configure(context, "AdministrationService");
JwtBearerConfigurationHelper.Configure(context, "AdministrationService"); //TODO: Should be "BasketService", but didn't work :(
// SwaggerConfigurationHelper.Configure(context, "Basket Service API");
SwaggerWithAuthConfigurationHelper.Configure(
@ -68,6 +69,11 @@ namespace EShopOnAbp.BasketService
opts.RemoteServiceName = "Basket";
});
});
Configure<AbpAntiForgeryOptions>(options =>
{
options.AutoValidate = false;
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -88,6 +94,10 @@ namespace EShopOnAbp.BasketService
// app.UseHttpMetrics();
app.UseAuthentication();
app.UseAbpClaimsMap();
app.Use(async (httpContext, func) =>
{
await func();
});
app.UseAuthorization();
app.UseSwagger();
app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Basket Service API"); });

4
services/basket/src/EShopOnAbp.BasketService.HttpApi.Host/appsettings.json

@ -1,7 +1,7 @@
{
"App": {
"SelfUrl": "https://localhost:44355",
"CorsOrigins": "https://localhost:44372,https://localhost:44373"
"CorsOrigins": "https://localhost:44372,https://localhost:44373,https://localhost:44335"
},
"AuthServer": {
"Authority": "https://localhost:44330",
@ -23,7 +23,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"AdministrationService": "Server=localhost,1434;Database=EShopOnAbp_Administration;User Id=sa;password=myPassw0rd;MultipleActiveResultSets=true"
"AdministrationService": "User ID=postgres;Password=myPassw0rd;Host=localhost;Port=5432;Database=EShopOnAbp_Administration;Pooling=false;"
},
"StringEncryption": {
"DefaultPassPhrase": "3PfxLgcuymUUbihz"

4
services/catalog/src/EShopOnAbp.CatalogService.Application.Contracts/Products/IPublicProductAppService.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
@ -7,5 +8,6 @@ namespace EShopOnAbp.CatalogService.Products
public interface IPublicProductAppService : IApplicationService
{
Task<ListResultDto<ProductDto>> GetListAsync();
Task<ProductDto> GetAsync(Guid id);
}
}

6
services/catalog/src/EShopOnAbp.CatalogService.Application/Products/PublicProductAppService.cs

@ -24,5 +24,11 @@ namespace EShopOnAbp.CatalogService.Products
)
);
}
public async Task<ProductDto> GetAsync(Guid id)
{
var product = await _productRepository.GetAsync(id);
return ObjectMapper.Map<Product, ProductDto>(product);
}
}
}

8
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Client/ClientProxies/PublicProductClientProxy.Generated.cs

@ -19,5 +19,13 @@ namespace EShopOnAbp.CatalogService.Products.ClientProxies
{
return await RequestAsync<ListResultDto<ProductDto>>(nameof(GetListAsync));
}
public virtual async Task<ProductDto> GetAsync(Guid id)
{
return await RequestAsync<ProductDto>(nameof(GetAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), id }
});
}
}
}

37
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Client/ClientProxies/catalog-generate-proxy.json

@ -302,6 +302,43 @@
},
"allowAnonymous": null,
"implementFrom": "EShopOnAbp.CatalogService.Products.IPublicProductAppService"
},
"GetAsyncById": {
"uniqueName": "GetAsyncById",
"name": "GetAsync",
"httpMethod": "GET",
"url": "api/catalog/public-product/{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.CatalogService.Products.ProductDto",
"typeSimple": "EShopOnAbp.CatalogService.Products.ProductDto"
},
"allowAnonymous": null,
"implementFrom": "EShopOnAbp.CatalogService.Products.IPublicProductAppService"
}
}
}

2
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs

@ -30,7 +30,7 @@ namespace EShopOnAbp.CatalogService
{
var configuration = context.Services.GetConfiguration();
JwtBearerConfigurationHelper.Configure(context, "CatalogService");
JwtBearerConfigurationHelper.Configure(context, "AdministrationService"); //TODO: Should be "CatalogService", but didn't work :(
// SwaggerConfigurationHelper.Configure(context, "Catalog Service API");
SwaggerWithAuthConfigurationHelper.Configure(

2
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json

@ -1,7 +1,7 @@
{
"App": {
"SelfUrl": "https://localhost:44354",
"CorsOrigins": "https://localhost:44372,https://localhost:44373"
"CorsOrigins": "https://localhost:44372,https://localhost:44373,https://localhost:44335"
},
"AuthServer": {
"Authority": "https://localhost:44330",

Loading…
Cancel
Save