Exemplo n.º 1
0
        public IActionResult ReadAll([FromQuery] ReadAllTimelinesDto readAllTimelinesDto)
        {
            ReadAllTimelinesResponseDto responseDto = null;

            try
            {
                if (_httpContextAccessor.GetCurrentUserId() != readAllTimelinesDto.AuthorId)
                {
                    throw new UnauthorizedAccessException($"Requested authorId does not match authenticated authorId.");
                }

                var lastReadAll         = readAllTimelinesDto.LastReadAll.HasValue ? readAllTimelinesDto.LastReadAll.Value : new DateTime(1970, 1, 1);
                var lastReadAllResponse = DateTime.Now;
                var timelines           = _timelineService.ReadAll(readAllTimelinesDto.AuthorId, lastReadAll);

                responseDto = new ReadAllTimelinesResponseDto
                {
                    Timelines   = timelines.Select(t => _mapper.Map <ReadTimelineResponseDto>(t)).ToArray(),
                    LastReadAll = lastReadAllResponse,
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Encountered exception while attempting to read all timelines.  Message: {ex.Message}");
                Console.WriteLine(ex.StackTrace);
                return(BadRequest(new ErrorResponseDto(ex)));
            }

            return(Ok(responseDto));
        }