Ejemplo n.º 1
0
        public async Task <ActionResult <List <Users> > > GetUsers(
            [FromQuery(Name = "limit")] string limit   = "1000",
            [FromQuery(Name = "offset")] string offset = "0",
            [FromQuery(Name = "search")] string search = ""
            )
        {
            if (!_authorizationService.ValidateJWTToken(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (limit != null && offset != null)
            {
                if (!int.TryParse(limit, out _) || !int.TryParse(offset, out _))
                {
                    var response = new JsonResponse
                    {
                        Message = "Invalid request",
                        Status  = 400,
                        Errors  = new Dictionary <string, string[]>
                        {
                            { "Queries", new string[] { "Invalid queries" } }
                        }
                    };

                    return(BadRequest(response.FormatResponse()));
                }
            }

            List <Users> users = await _usersContext.Browse(limit, offset, search);

            return(Ok(new { users }));
        }
        public async Task <IEnumerable <Users> > GetAll()
        {
            List <Users> users;

            if (_context != null)
            {
                users = await _context.Users.ToListAsync();

                return(users.WithoutPasswords());
            }

            users = await _usersContext.Browse();

            return(users.WithoutPasswords());
        }