Ejemplo n.º 1
0
        public static void Process(HttpContext context)
        {
            if (FilterQueryParser.TryParse(context.Request.Query, ref _query))
            {
                context.Response.ContentType = "application/json";
                if (_query.WillYieldZeroResults)
                {
                    context.Response.ContentLength = FastJson.EmptyAccounts.Length;
                    context.Response.Body.Write(FastJson.EmptyAccounts);
                    return;
                }

                HList <Account> result = _query.ExecuteFilter();

                ParseContext stream = Buffer.Context;

                FastJson.WriteFilterResponse(result, _query.Fields, ref stream);

                context.Response.ContentLength = stream.WrittenLength;
                context.Response.Body.Write(stream.WrittenSpan);

                return;
            }

            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
Ejemplo n.º 2
0
        public static void Process(HttpContext context, uint accountId)
        {
            if (!Database.TryGetAccount(accountId, out Account account))
            {
                context.Response.StatusCode = StatusCodes.Status404NotFound;
                return;
            }

            if (SuggestQueryParser.TryParse((QueryCollection)context.Request.Query, ref _query))
            {
                context.Response.ContentType = "application/json";
                if (_query.WillYieldZeroResults)
                {
                    context.Response.ContentLength = FastJson.EmptyAccounts.Length;
                    context.Response.Body.Write(FastJson.EmptyAccounts);
                    return;
                }

                HList <Account> result = _query.Execute(account);

                ParseContext stream = Buffer.Context;
                FastJson.WriteFilterResponse(result, Fields, ref stream, (a, f) => Filter(a, f));

                context.Response.ContentLength = stream.WrittenLength;
                context.Response.Body.Write(stream.WrittenSpan);

                return;
            }

            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }