protected ControllerBase(IStringContentService stringContentService, IOptions <PostgRestConfig> options)
 {
     this.StringContentService = stringContentService;
     this.options     = options;
     query            = null;
     body             = null;
     info             = null;
     stringParameters = new List <string>();
     npngParameters   = new List <NpgsqlParameter>();
 }
        protected async Task <ContentResult> GetContentAsync()
        {
            info = GetInfo();
            if (info == null)
            {
                return(new ContentResult {
                    StatusCode = 400
                });
            }
            info.Options.SetResponseParameters(info, StringContentService);
            if (info.Parameters.Count == 0)
            {
                return(await Execute());
            }

            foreach (var param in info.Parameters)
            {
                if (param.Direction == "OUT")
                {
                    continue;
                }

                if (info.MatchParamsByQueryStringKey)
                {
                    ParseMatchParamsByQueryStringKeyName(param);
                }
                else if (info.MatchParamsByFormKey)
                {
                    ParseMatchParamsByBFormKeyName(param);
                }
                else if (param.FromQueryString)
                {
                    ParseParamFromQueryString(param);
                }
                else if (param.FromBody)
                {
                    await ParseParamFromBody(param);
                }
                else
                {
                    ParseCustomParam(param);
                }
                stringParameters.Add($"@{param.ParamName}::{param.ParamType}");
            }

            return(await Execute());
        }
        private void AddControllerFeature(ControllerFeature feature, ControllerInfo info)
        {
            var name        = $"Proxy{info.RoutineName.GetHashCode()}_{Guid.NewGuid().ToString().Split('-').First()}";
            var typeBuilder = moduleBuilder.DefineType(name, TypeAttributes.Public);
            var type        = typeBuilder.CreateTypeInfo();

            feature.Controllers.Add(info.RouteType.MakeGenericType(type).GetTypeInfo());
            info.Options = options;
            info.MatchParamsByQueryStringKey = options.MatchParamsByQueryStringKeyWhen?.Invoke(info) ?? false;
            info.MatchParamsByFormKey        = options.MatchParamsByFormKeyWhen?.Invoke(info) ?? false;
            if (!info.MatchParamsByQueryStringKey && !info.MatchParamsByFormKey)
            {
                info.RouteName = string.Concat(info.RouteName,
                                               string.Join("",
                                                           info.Parameters.Where(p => !p.FromQueryString && !p.FromBody && p.Direction == "IN").Select(p => $"{{{p.ParamName}}}/")));
            }
            var verb       = info.Verb.ToString().ToUpper();
            var paramsDesc = info.Parameters.Select(
                p =>
            {
                var comment = "";
                if (p.FromQueryString)
                {
                    comment = string.Concat(comment, "/*from query string*/");
                }
                if (p.FromBody)
                {
                    comment = string.Concat(comment, "/*from body*/");
                }
                return($"{comment}{p.Direction} {p.ParamName} {p.ParamType}");
            })
                             .ToArray();
            var routine = $"function {info.RoutineName}({string.Join(", ", paramsDesc)}) returns {info.ReturnType}";

            logger.LogInformation($"Mapping PostgreSQL routine \"{routine}\" to REST API endpoint \"{verb} {info.RouteName}\" ... \n");
            ControllerData.Data.TryAdd(name, info);
        }