예제 #1
0
        public async Task <bool> UpdateProduct(int userId, ProductDto productDto)
        {
            // TODO: [TESTS] (ProductService.UpdateProduct) Add tests
            // TODO: [VALIDATION] (ProductService.UpdateProduct) Ensure that user owns this product
            var builder = new ServiceMetricBuilder(nameof(ProductService), nameof(UpdateProduct))
                          .WithCategory(MetricCategory.Product, MetricSubCategory.Update)
                          .WithCustomInt1(userId)
                          .WithCustomInt2(productDto.ClientId);

            try
            {
                using (builder.WithTiming())
                {
                    if (productDto.UserId != userId)
                    {
                        // TODO: [HANDLE] (ProductService.UpdateProduct) Handle this better
                        return(false);
                    }

                    using (builder.WithCustomTiming1())
                    {
                        builder.IncrementQueryCount();
                        if (await _productRepo.Update(productDto.AsProductEntity()) <= 0)
                        {
                            return(false);
                        }

                        builder.WithResultsCount(1);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogUnexpectedException(ex);
                builder.WithException(ex);
                return(false);
            }
            finally
            {
                await _metrics.SubmitPointAsync(builder.Build());
            }
        }