5 changed files with 93 additions and 1 deletions
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using EShopOnAbp.CatalogService.Products; |
||||
|
using Grpc.Core; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.ObjectMapping; |
||||
|
|
||||
|
namespace EShopOnAbp.CatalogService.Grpc; |
||||
|
|
||||
|
public class PublicProductGrpService : ProductPublic.ProductPublicBase |
||||
|
{ |
||||
|
private readonly IRepository<Product, Guid> _productRepository; |
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
public PublicProductGrpService(IRepository<Product, Guid> productRepository, IObjectMapper objectMapper) |
||||
|
{ |
||||
|
_productRepository = productRepository; |
||||
|
_objectMapper = objectMapper; |
||||
|
} |
||||
|
|
||||
|
public override async Task<ProductDto> GetAsync(ProductRequest request, ServerCallContext context) |
||||
|
{ |
||||
|
var product = await _productRepository.GetAsync(Guid.Parse(request.Id)); |
||||
|
return _objectMapper.Map<Product, ProductDto>(product); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
syntax = "proto3"; |
||||
|
|
||||
|
option csharp_namespace = "EShopOnAbp.CatalogService.Grpc"; |
||||
|
|
||||
|
package CatalogApi; |
||||
|
|
||||
|
service ProductPublic { |
||||
|
rpc GetAsync(ProductRequest) returns (ProductDto) {} |
||||
|
} |
||||
|
|
||||
|
message ProductRequest { |
||||
|
string id = 1; |
||||
|
} |
||||
|
|
||||
|
message ProductDto { |
||||
|
string id = 1; |
||||
|
string code = 2; |
||||
|
string name = 3; |
||||
|
float price = 4; |
||||
|
int32 stockCount = 5; |
||||
|
} |
||||
Loading…
Reference in new issue