コード例 #1
0
        public async Task <IActionResult> GetById(string id)
        {
            try
            {
                var response = await _facade.Get(id);

                if (response == null)
                {
                    return(NotFound());
                }

                return(Ok(response));
            }
            catch (Exception exception)
            {
                var errorId = _newIdGenerator.Generate();
                return(StatusCode(500, $"Failed to process request. Error code {errorId}"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetById(string id, SortOption?sort = SortOption.None)
        {
            try
            {
                var response = await _entityManager.Get(id, sort);

                if (response == null)
                {
                    return(NotFound());
                }

                return(Ok(response));
            }
            catch (Exception exception)
            {
                var errorId = _newIdGenerator.Generate();
                var message = $"Failed to process request. Error code {errorId}";
                _logger.LogError(exception, message);
                return(StatusCode(500, message));
            }
        }
コード例 #3
0
        public async Task <TextPieceResponceV1> Create(CreateMemoRequestV1 request)
        {
            var id         = _newIdGenerator.Generate();
            var paragraphs = request.TextFragment.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(s => new TextParagraphEntity {
                ParagraphText = s
            })
                             .ToList();
            var textStatistics = _textStatisticsCalculator.CalculateStatistics(paragraphs);
            var entity         = new TextPieceEntity
            {
                Id            = id,
                Paragraphs    = paragraphs,
                Statistics    = textStatistics,
                CreatedAtUtc  = DateTime.UtcNow,
                ModifiedAtUtc = DateTime.UtcNow
            };

            await _repository.SaveAsync(entity);

            return(EntityMapper.ToV1Response(entity));
        }
コード例 #4
0
        public async Task <Dtos.V2.TextPieceResponceV2> Create(Dtos.V2.CreateMemoRequestV2 request)
        {
            var id             = _newIdGenerator.Generate();
            var textParagraphs = request.Paraagraphs.Select(s => s.ParagraphText).ToArray();

            textParagraphs = DoSort(request.Sort, textParagraphs).ToArray();
            var paragraphs = textParagraphs.Select(s => new TextParagraphEntity {
                ParagraphText = s
            }).ToList();
            var textStatistics = _textStatisticsCalculator.CalculateStatistics(paragraphs);
            var entity         = new TextPieceEntity
            {
                Id            = id,
                Paragraphs    = paragraphs,
                Statistics    = textStatistics,
                CreatedAtUtc  = DateTime.UtcNow,
                ModifiedAtUtc = DateTime.UtcNow
            };

            await _repository.SaveAsync(entity);

            return(EntityMapper.ToV2Response(entity));
        }