Skip to content

Commit

Permalink
Cart funcntionality integrated with backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Jan 26, 2024
1 parent d232b5a commit 3e96b97
Show file tree
Hide file tree
Showing 39 changed files with 274 additions and 219 deletions.
3 changes: 2 additions & 1 deletion src/backend/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- identity-db
ports:
- "5001:80"
restart: always

checkout-api:
image: restaurant/checkout-api
Expand Down Expand Up @@ -96,4 +97,4 @@ services:
image: redis:alpine

volumes:
database-data:
database-data:
6 changes: 3 additions & 3 deletions src/backend/services/cart-api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func main() {
// tracedProducer := otelsarama.WrapSyncProducer(nil, p)
// defer tracedProducer.Close()

basketRepository := repositories.NewCartRepository(redisClient)
cartHandler := handlers.NewCartHandler(basketRepository)
cartRepository := repositories.NewCartRepository(redisClient)
cartHandler := handlers.NewCartHandler(cartRepository)

apiV1 := router.Group(basePath + "/api/v1")
{
Expand All @@ -123,7 +123,7 @@ func main() {
c.URL = basePath + "/swagger/doc.json"
}))

go grpcServer(grpcsvc.NewCartGrpcService(basketRepository))
go grpcServer(grpcsvc.NewCartGrpcService(cartRepository))
_ = router.Run()
}

Expand Down
20 changes: 10 additions & 10 deletions src/backend/services/cart-api/internal/grpc/cart_service_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var _ pbv1.CartServiceServer = (*cartGrpcService)(nil)

type CartGetter interface {
Get(ctx context.Context, customerID string) (*models.Cart, error)
Get(ctx context.Context, cartID string) (*models.Cart, error)
}

type cartGrpcService struct {
Expand All @@ -23,28 +23,28 @@ func NewCartGrpcService(cartGetter CartGetter) pbv1.CartServiceServer {
}
}

func mapBasketToCartResponse(basket *models.Cart) *pbv1.GetCustomerCartResponse {
func mapBasketToCartResponse(cart *models.Cart) *pbv1.GetCartResponse {
var cartItems []*pbv1.CartItem
for _, basketItem := range basket.LineItems {
for _, basketItem := range cart.LineItems {
cartItems = append(cartItems, &pbv1.CartItem{
ItemId: int64(basketItem.ItemID),
Price: basketItem.UnitPrice,
Quantity: int64(basketItem.Quantity),
})
}

return &pbv1.GetCustomerCartResponse{
CustomerId: basket.ID.String(),
Items: cartItems,
return &pbv1.GetCartResponse{
CartId: cart.ID.String(),
Items: cartItems,
}
}

// GetCustomerCart implements v1.CartServiceServer
func (s *cartGrpcService) GetCustomerCart(
func (s *cartGrpcService) GetCart(
ctx context.Context,
req *pbv1.GetCustomerCartRequest,
) (*pbv1.GetCustomerCartResponse, error) {
customerBasket, err := s.getter.Get(ctx, req.GetCustomerId())
req *pbv1.GetCartRequest,
) (*pbv1.GetCartResponse, error) {
customerBasket, err := s.getter.Get(ctx, req.GetCartId())
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions src/backend/services/cart-api/pb/cart.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ option java_outer_classname = "CartService";
option java_package = "org.jurabek";

service CartService {
rpc GetCustomerCart(GetCustomerCartRequest) returns (GetCustomerCartResponse);
rpc GetCart(GetCartRequest) returns (GetCartResponse);
}

message GetCustomerCartRequest {
string customer_id = 1;
message GetCartRequest {
string cart_id = 1;
}

message GetCustomerCartResponse {
string customer_id = 1;
message GetCartResponse {
string cart_id = 1;
repeated CartItem items = 2;
}

Expand Down
97 changes: 47 additions & 50 deletions src/backend/services/cart-api/pb/v1/cart.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e96b97

Please sign in to comment.