committed by
GitHub
14 changed files with 154 additions and 12 deletions
@ -0,0 +1,32 @@ |
|||
syntax = "proto3"; |
|||
|
|||
/* >> |
|||
import "google/api/annotations.proto"; |
|||
<< */ |
|||
|
|||
option csharp_namespace = "EShopOnAbp.CatalogService.Grpc"; |
|||
|
|||
package CatalogApi; |
|||
|
|||
service ProductPublic { |
|||
rpc GetById(ProductRequest) returns (ProductResponse) { |
|||
/* >> |
|||
option (google.api.http) = { |
|||
get: "/api/catalog/product/{id}" |
|||
}; |
|||
<< */ |
|||
} |
|||
} |
|||
|
|||
message ProductRequest { |
|||
string id = 1; |
|||
} |
|||
|
|||
message ProductResponse { |
|||
string id = 1; |
|||
string code = 2; |
|||
string name = 3; |
|||
string imageName = 4; |
|||
float price = 5; |
|||
int32 stockCount = 6; |
|||
} |
|||
@ -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<ProductResponse> GetById(ProductRequest request, ServerCallContext context) |
|||
{ |
|||
var product = await _productRepository.GetAsync(Guid.Parse(request.Id)); |
|||
return _objectMapper.Map<Product, ProductResponse>(product); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue