public CentralDeErrosQuery(IErrorLogAppService errorLogAppService)
        {
            Field <ListGraphType <ErrorLogType> >(
                "errorlogs",
                description: "Query utilizada para consultar os logs de erro.",
                arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <ErrorLogFilterInputType>
                {
                    Name = "filter"
                },
                new QueryArgument <OrderByType> {
                    Name = "orderBy"
                }
            }),
                resolve: context =>
            {
                var user    = (ClaimsPrincipal)context.UserContext;
                var orderBy = context.GetArgument <OrderErrorLogByField?>("orderBy");
                var filter  = context.GetArgument <ErrorLogFilter?>("filter");

                return(errorLogAppService.GetErrorLogs(filter, orderBy));
            }
                );
        }
Exemplo n.º 2
0
        public ActionResult <ErrorLogViewModel> Get()
        {
            var code        = HttpContext.Request.Query["code"];
            var message     = HttpContext.Request.Query["message"];
            var level       = HttpContext.Request.Query["level"];
            var archieved   = HttpContext.Request.Query["archieved"];
            var origin      = HttpContext.Request.Query["origin"];
            var environment = HttpContext.Request.Query["environment"];
            var orderby     = HttpContext.Request.Query["orderby"];

            ErrorLogFilter filter = new ErrorLogFilter();

            if (code.Count > 0)
            {
                filter.Code = code;
            }
            if (message.Count > 0)
            {
                filter.Message = message;
            }
            if (level.Count > 0)
            {
                filter.Level = level;
            }
            if (origin.Count > 0)
            {
                filter.Origin = origin;
            }
            if (archieved.Count > 0)
            {
                filter.Archieved = archieved == "true" ? true : false;
            }

            if (environment.Count > 0)
            {
                if (environment.ToString().ToLower() == "unknown")
                {
                    filter.Environment = ServerEnvironment.Unknown;
                }
                else if (environment.ToString().ToLower() == "development")
                {
                    filter.Environment = ServerEnvironment.Development;
                }
                else if (environment.ToString().ToLower() == "test")
                {
                    filter.Environment = ServerEnvironment.Test;
                }
                else if (environment.ToString().ToLower() == "acceptance")
                {
                    filter.Environment = ServerEnvironment.Acceptance;
                }
                else if (environment.ToString().ToLower() == "production")
                {
                    filter.Environment = ServerEnvironment.Production;
                }
                else
                {
                    return(BadRequest("Filtros informados são inválidos!"));
                }
            }

            OrderErrorLogByField orderErrorLogBy = OrderErrorLogByField.Any;

            if (orderby.Count > 0)
            {
                if (orderby.ToString().ToLower() == "code")
                {
                    orderErrorLogBy = OrderErrorLogByField.Code;
                }
                else if (orderby.ToString().ToLower() == "level")
                {
                    orderErrorLogBy = OrderErrorLogByField.Level;
                }
                else if (orderby.ToString().ToLower() == "message")
                {
                    orderErrorLogBy = OrderErrorLogByField.Message;
                }
                else
                {
                    return(BadRequest("Ordenação inválida!"));
                }
            }

            return(Ok(_errorLogAppService.GetErrorLogs(filter, orderErrorLogBy)));
        }