mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-7] add metrics, tracing
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"route256/cart/internal/domain/entity"
|
||||
"route256/cart/internal/domain/model"
|
||||
"route256/cart/internal/infra/tracing"
|
||||
)
|
||||
|
||||
//go:generate minimock -i Repository -o ./mock -s _mock.go
|
||||
@@ -43,6 +44,9 @@ func NewCartService(repository Repository, productService ProductService, lomsSe
|
||||
}
|
||||
|
||||
func (s *CartService) AddItem(ctx context.Context, userID entity.UID, item *model.Item) error {
|
||||
ctx, span := tracing.Tracer().Start(ctx, "AddItem")
|
||||
defer span.End()
|
||||
|
||||
if err := item.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid requested values: %w", err)
|
||||
}
|
||||
@@ -76,6 +80,9 @@ func (s *CartService) AddItem(ctx context.Context, userID entity.UID, item *mode
|
||||
// and return a list of the collected items.
|
||||
// In case of failed request to product-service, return nothing and error.
|
||||
func (s *CartService) GetItemsByUserID(ctx context.Context, userID entity.UID) (*model.Cart, error) {
|
||||
ctx, span := tracing.Tracer().Start(ctx, "GetItemsByUserID")
|
||||
defer span.End()
|
||||
|
||||
if userID <= 0 {
|
||||
return nil, fmt.Errorf("userID invalid")
|
||||
}
|
||||
@@ -122,6 +129,9 @@ func (s *CartService) GetItemsByUserID(ctx context.Context, userID entity.UID) (
|
||||
}
|
||||
|
||||
func (s *CartService) DeleteItem(ctx context.Context, userID entity.UID, sku entity.Sku) error {
|
||||
ctx, span := tracing.Tracer().Start(ctx, "DeleteItem")
|
||||
defer span.End()
|
||||
|
||||
if userID <= 0 {
|
||||
return fmt.Errorf("userID invalid")
|
||||
}
|
||||
@@ -138,6 +148,9 @@ func (s *CartService) DeleteItem(ctx context.Context, userID entity.UID, sku ent
|
||||
}
|
||||
|
||||
func (s *CartService) DeleteItemsByUserID(ctx context.Context, userID entity.UID) error {
|
||||
ctx, span := tracing.Tracer().Start(ctx, "DeleteItemsByUserID")
|
||||
defer span.End()
|
||||
|
||||
if userID <= 0 {
|
||||
return fmt.Errorf("userID invalid")
|
||||
}
|
||||
@@ -150,6 +163,9 @@ func (s *CartService) DeleteItemsByUserID(ctx context.Context, userID entity.UID
|
||||
}
|
||||
|
||||
func (s *CartService) CheckoutUserCart(ctx context.Context, userID entity.UID) (int64, error) {
|
||||
ctx, span := tracing.Tracer().Start(ctx, "CheckoutUserCart")
|
||||
defer span.End()
|
||||
|
||||
if userID <= 0 {
|
||||
return 0, fmt.Errorf("userID invalid")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user