Exemplo n.º 1
0
        public async Task <ProjectDto> GetById(int userId, int projectId)
        {
            // TODO: [TESTS] (ProjectService.GetById) Add tests
            var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(GetById))
                          .WithCategory(MetricCategory.Project, MetricSubCategory.GetById)
                          .WithCustomInt1(userId)
                          .WithCustomInt2(0)
                          .WithCustomInt3(projectId);

            try
            {
                using (builder.WithTiming())
                {
                    ProjectEntity dbEntry;
                    using (builder.WithCustomTiming1())
                    {
                        builder.IncrementQueryCount();
                        dbEntry = await _projectRepo.GetById(projectId);

                        builder.CountResult(dbEntry);
                    }

                    if (dbEntry == null)
                    {
                        // TODO: [HANDLE] (ProjectService.GetById) Handle this
                        return(null);
                    }

                    builder.WithCustomInt2(dbEntry.ProductId);
                    if (dbEntry.UserId != userId)
                    {
                        // TODO: [HANDLE] (ProjectService.GetById) Handle this
                        return(null);
                    }

                    return(ProjectDto.FromEntity(dbEntry));
                }
            }
            catch (Exception ex)
            {
                _logger.LogUnexpectedException(ex);
                builder.WithException(ex);
                return(null);
            }
            finally
            {
                await _metrics.SubmitPointAsync(builder.Build());
            }
        }