Partial checkin
This commit is contained in:
parent
9b1c690c9e
commit
016089fb5f
@ -1,5 +1,4 @@
|
||||
using grpc;
|
||||
using Grpc.Net.Client;
|
||||
using Grpc.Net.Client;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -8,7 +7,8 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static grpc.Basket;
|
||||
using GrpcBasket;
|
||||
using Grpc.Core;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
@ -27,49 +27,57 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
{
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GetById @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Http2UnencryptedSupport disable @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Http2UnencryptedSupport disable @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
_httpClient.BaseAddress = new Uri("http://localhost:5001");
|
||||
httpClient.BaseAddress = new Uri("http://localhost:5580");
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ {_httpClient.BaseAddress} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", _httpClient.BaseAddress);
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ {httpClient.BaseAddress} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " + httpClient.BaseAddress, httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<BasketClient>(_httpClient);
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(httpClient);
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ client create @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ client create @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id });
|
||||
try
|
||||
{
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ call grpc server @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id });
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ call grpc server @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
_logger.LogInformation("############## DATA: {@a}", response.Buyerid);
|
||||
_logger.LogInformation("############## DATA: {@a}", response.Buyerid);
|
||||
_logger.LogInformation("############## DATA:response {@response}", response);
|
||||
|
||||
//if (streaming.IsCompleted)
|
||||
//{
|
||||
// _logger.LogInformation("############## DATA: {@a}", streaming.GetResult());
|
||||
//}
|
||||
//var streaming = client.GetBasketById(new BasketRequest { Id = id });
|
||||
return MapToBasketData(response);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
_logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null; // temp
|
||||
// var data = await _apiClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
// var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||
|
||||
//var status = streaming.GetStatus();
|
||||
|
||||
//if (status.StatusCode == Grpc.Core.StatusCode.OK)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
|
||||
return null;
|
||||
//return MapToBasketData(response.ResponseStream);
|
||||
// return basket;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket());
|
||||
|
||||
var client = GrpcClient.Create<BasketClient>(_httpClient);
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(_httpClient);
|
||||
var request = MapToCustomerBasketRequest(currentBasket);
|
||||
|
||||
await client.UpdateBasketAsync(request);
|
||||
|
@ -74,6 +74,17 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
|
||||
app.UseCors("CorsPolicy");
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseSwagger().UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
||||
|
||||
c.OAuthClientId("mobileshoppingaggswaggerui");
|
||||
c.OAuthClientSecret(string.Empty);
|
||||
c.OAuthRealm(string.Empty);
|
||||
c.OAuthAppName("Purchase BFF Swagger UI");
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
@ -91,16 +102,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
});
|
||||
|
||||
app.UseSwagger().UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
||||
|
||||
c.OAuthClientId("mobileshoppingaggswaggerui");
|
||||
c.OAuthClientSecret(string.Empty);
|
||||
c.OAuthRealm(string.Empty);
|
||||
c.OAuthAppName("Purchase BFF Swagger UI");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,8 +131,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
{
|
||||
Implicit = new OpenApiOAuthFlow()
|
||||
{
|
||||
AuthorizationUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
||||
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||
// AuthorizationUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
||||
// TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||
|
||||
AuthorizationUrl = new Uri($"http://localhost:5105/connect/authorize"),
|
||||
TokenUrl = new Uri($"http://localhost:5105/connect/token"),
|
||||
Scopes = new Dictionary<string, string>()
|
||||
{
|
||||
{ "mobileshoppingagg", "Shopping Aggregator for Mobile Clients" }
|
||||
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
{
|
||||
@ -30,13 +31,18 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
[ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data)
|
||||
{
|
||||
Log.Information("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ UpdateAllBasketAsync @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
if (data.Items == null || !data.Items.Any())
|
||||
{
|
||||
return BadRequest("Need to pass at least one basket line");
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
Log.Information("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GetByIdAsync @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
var basket = await _basket.GetByIdAsync(data.BuyerId) ?? new BasketData(data.BuyerId);
|
||||
Log.Information("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ basket @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
var catalogItems = await _catalog.GetCatalogItemsAsync(data.Items.Select(x => x.ProductId));
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "GrpcBasket";
|
||||
|
||||
package BasketApi;
|
||||
|
||||
service Basket {
|
||||
rpc GetBasketById(BasketRequest) returns (CustomerBasketResponse);
|
||||
rpc UpdateBasket(CustomerBasketRequest) returns (CustomerBasketResponse);
|
||||
}
|
||||
|
||||
message BasketRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message CustomerBasketRequest {
|
||||
string buyerid = 1;
|
||||
repeated BasketItemResponse items = 2;
|
||||
}
|
||||
|
||||
message CustomerBasketResponse {
|
||||
string buyerid = 1;
|
||||
repeated BasketItemResponse items = 2;
|
||||
}
|
||||
|
||||
message BasketItemResponse {
|
||||
string id = 1;
|
||||
string productid = 2;
|
||||
string productname = 3;
|
||||
double unitprice = 4;
|
||||
double oldunitprice = 5;
|
||||
int32 quantity = 6;
|
||||
string pictureurl = 7;
|
||||
}
|
@ -23,10 +23,66 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<BasketData> GetByIdAsync(string id)
|
||||
{
|
||||
var data = await _apiClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||
|
||||
return basket;
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GetById @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Http2UnencryptedSupport disable @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
httpClient.BaseAddress = new Uri("http://localhost:5580");
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ {httpClient.BaseAddress} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<BasketClient>(httpClient);
|
||||
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ client create @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
try{
|
||||
|
||||
var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id });
|
||||
_logger.LogInformation("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ call grpc server @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
_logger.LogInformation("############## DATA: {@a}", response.Buyerid);
|
||||
_logger.LogInformation("############## DATA:response {@response}", response);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
Console.WriteLine($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
_logger.logError($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
//if (streaming.IsCompleted)
|
||||
//{
|
||||
// _logger.LogInformation("############## DATA: {@a}", streaming.GetResult());
|
||||
//}
|
||||
//var streaming = client.GetBasketById(new BasketRequest { Id = id });
|
||||
|
||||
|
||||
//var status = streaming.GetStatus();
|
||||
|
||||
//if (status.StatusCode == Grpc.Core.StatusCode.OK)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// var data = await _apiClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
// var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||
|
||||
// return basket;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
|
@ -94,6 +94,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
{
|
||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
||||
//c.ConfigureOAuth2("Microsoft.eShopOnContainers.Web.Shopping.HttpAggregatorwaggerui", "", "", "Purchase BFF Swagger UI");
|
||||
c.OAuthClientId("webshoppingaggswaggerui");
|
||||
c.OAuthAppName("web shopping bff Swagger UI");
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -157,7 +159,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
TokenUrl = $"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
|
||||
Scopes = new Dictionary<string, string>()
|
||||
{
|
||||
{ "webshoppingagg", "Shopping Aggregator for Web Clients" }
|
||||
{ "webshoppingagg", "Shopping Aggregator for Web Clients" },
|
||||
{ "basket", "basket api" }
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -55,6 +55,13 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- grpc -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="$(Google_Protobuf)" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="$(Grpc_Net_Client)" />
|
||||
<PackageReference Include="Grpc.Tools" Version="$(Grpc_Tools)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\BuildingBlocks\Devspaces.Support\Devspaces.Support.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -284,7 +284,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration
|
||||
|
||||
AllowedScopes =
|
||||
{
|
||||
"webshoppingagg"
|
||||
"webshoppingagg",
|
||||
"basket"
|
||||
}
|
||||
},
|
||||
new Client
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
<PropertyGroup Label="Package Versions">
|
||||
<Grpc_AspNetCore_Server>0.1.22-pre3</Grpc_AspNetCore_Server>
|
||||
<Grpc_Net_Client>0.1.22-pre3</Grpc_Net_Client>
|
||||
<Google_Protobuf>3.9.1</Google_Protobuf>
|
||||
<Grpc_Tools>2.23.0</Grpc_Tools>
|
||||
<Grpc_AspNetCore_Server_ClientFactory>0.1.22-pre2</Grpc_AspNetCore_Server_ClientFactory>
|
||||
|
Loading…
x
Reference in New Issue
Block a user