Ejemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] string offset)
        {
            var userIndex = await _mediator.Send(new GetUserList(offset));

            var(_, userIndexDto) = _mapper.MapTo <UserIndexDto>(userIndex);
            return(new ObjectResult(ForUserIndexPage(userIndexDto)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetUser(Guid userId, [FromHeader(Name = "If-None-Match")] string etag)
        {
            var userResult = await _mediator.Send(new GetUserById(userId, etag));

            var response = userResult switch
            {
                UserFound userFound => GetUserFoundResult(userFound),
                UserNotModified _ => new StatusCodeResult((int)HttpStatusCode.NotModified),
                UserNotFound _ => NotFound(),
                _ => throw new ArgumentOutOfRangeException(nameof(userResult))
            };

            return(response);

            IActionResult GetUserFoundResult(UserFound userFound)
            {
                var(errorMessage, userDto) = _mapper.MapTo <UserDto>(userFound.User);
                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    throw new Exception(errorMessage);
                }
                return(new ObjectResult(ForExistingUser(userDto, userFound.Etag)));
            }
        }