Skip to content

Commit

Permalink
re-adds CartService definition and reference (open-telemetry#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
puckpuck authored Jun 17, 2022
1 parent cc0325e commit c9616cd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ services:
- REDIS_ADDR
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_RESOURCE_ATTRIBUTES=service.name=cartservice
- ASPNETCORE_URLS=http://*:${CART_SERVICE_PORT}
depends_on:
- redis-cart
- otelcol
Expand Down
6 changes: 6 additions & 0 deletions src/cartservice/src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*.sh
**/*.bat
**/bin/
**/obj/
**/out/
Dockerfile*
1 change: 0 additions & 1 deletion src/cartservice/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ FROM mcr.microsoft.com/dotnet/runtime-deps:6.0.5-alpine3.15-amd64
WORKDIR /usr/src/app/
COPY --from=builder /cartservice/ ./

ENV ASPNETCORE_URLS http://*:${CART_SERVICE_PORT}
EXPOSE ${CART_SERVICE_PORT}

ENTRYPOINT [ "./cartservice" ]
4 changes: 2 additions & 2 deletions src/cartservice/src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using cartservice.cartstore;
using Hipstershop;
using cartservice.services;
using OpenTelemetry.Trace;

namespace cartservice;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<Hipstershop.Cart>();
endpoints.MapGrpcService<CartService>();
endpoints.MapGrpcHealthChecksService();
endpoints.MapGet("/", async context =>
Expand Down
49 changes: 49 additions & 0 deletions src/cartservice/src/services/CartService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Threading.Tasks;
using Grpc.Core;
using cartservice.cartstore;
using Hipstershop;

namespace cartservice.services
{
public class CartService : Hipstershop.CartService.CartServiceBase
{
private readonly static Empty Empty = new Empty();
private readonly ICartStore _cartStore;

public CartService(ICartStore cartStore)
{
_cartStore = cartStore;
}

public async override Task<Empty> AddItem(AddItemRequest request, ServerCallContext context)
{
await _cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity);
return Empty;
}

public override Task<Cart> GetCart(GetCartRequest request, ServerCallContext context)
{
return _cartStore.GetCartAsync(request.UserId);
}

public async override Task<Empty> EmptyCart(EmptyCartRequest request, ServerCallContext context)
{
await _cartStore.EmptyCartAsync(request.UserId);
return Empty;
}
}
}

0 comments on commit c9616cd

Please sign in to comment.