This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
public static class SqlSelectBuilder
|
||||
{
|
||||
|
||||
//Build the SELECT portion of a list query based on the template, mini or full and the object key in question
|
||||
public static string Build(List<AyaObjectFieldDefinition> objectFieldsList, string template, bool mini)
|
||||
{
|
||||
|
||||
//parse the template
|
||||
var jtemplate = JObject.Parse(template);
|
||||
|
||||
|
||||
//convert to strings array (https://stackoverflow.com/a/33836599/8939)
|
||||
string[] templateFieldList;
|
||||
if (mini)
|
||||
{
|
||||
templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
|
||||
}
|
||||
else
|
||||
{
|
||||
templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("SELECT ");
|
||||
|
||||
//Default ID column for each row (always is aliased as df)
|
||||
AyaObjectFieldDefinition def = objectFieldsList.FirstOrDefault(x => x.FieldKey == "df");
|
||||
if (def == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("SqlSelectBuilder: objectFieldList is missing the df default field");
|
||||
}
|
||||
if (string.IsNullOrEmpty(def.SqlIdColumnName))
|
||||
{
|
||||
sb.Append("id");//default when no alternate column is specified
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(def.SqlIdColumnName);
|
||||
}
|
||||
|
||||
sb.Append(" AS df");
|
||||
|
||||
foreach (string ColumnName in templateFieldList)
|
||||
{
|
||||
AyaObjectFieldDefinition o = objectFieldsList.FirstOrDefault(x => x.FieldKey == ColumnName);
|
||||
#if (DEBUG)
|
||||
//Developers little helper
|
||||
if (o == null)
|
||||
{
|
||||
throw new System.ArgumentNullException($"DEV ERROR in SqlSelectBuilder.cs: field {ColumnName} specified in template was NOT found in ObjectFields list");
|
||||
}
|
||||
#endif
|
||||
if (o != null)
|
||||
{//Ignore missing fields in production
|
||||
|
||||
sb.Append(", ");
|
||||
sb.Append(o.GetSqlValueColumnName());
|
||||
|
||||
//does it also have an ID column?
|
||||
if (!string.IsNullOrWhiteSpace(o.SqlIdColumnName))
|
||||
{
|
||||
sb.Append(", ");
|
||||
sb.Append(o.SqlIdColumnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
@@ -9,6 +9,7 @@ using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using System.Collections.Generic;
|
||||
using AyaNova.DataList;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -406,6 +407,8 @@ namespace AyaNova.Biz
|
||||
#region TestGetWidgetUserEmailList
|
||||
internal async Task<ApiPagedResponse> TestGetWidgetUserEmailList(IUrlHelper Url, string routeName, ListOptions listOptions)
|
||||
{
|
||||
//var dlist=AyaNova.DataList.DataListFactory.GetListOfAllDataListKeyNames();
|
||||
|
||||
//TODO: Get template (MOCKED FOR NOW UNTIL PROOF OF CONCEPT)
|
||||
var MOCK_WIDGET_USER_EMAIL_DISPLAY_TEMPLATE_JSON = @"
|
||||
{
|
||||
@@ -414,8 +417,9 @@ namespace AyaNova.Biz
|
||||
}
|
||||
";
|
||||
|
||||
var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
|
||||
|
||||
// var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
|
||||
var DataList=DataListFactory.GetAyaDataList(nameof(TestWidgetUserEmailDataList));
|
||||
|
||||
|
||||
//TODO: PUt this in the template biz class ultimately and modify sqlselectbuilder to use it
|
||||
|
||||
|
||||
Reference in New Issue
Block a user