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}")); } }
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)); } }
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)); }
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)); }