This commit is contained in:
2020-01-17 22:05:49 +00:00
parent fb0f64ef1e
commit 0866c7112d
3 changed files with 133 additions and 124 deletions

View File

@@ -19,12 +19,16 @@ GRID LISTS TODO NOW:
- Once both lists are working: - Once both lists are working:
- abstract away the commonalities into other classes - abstract away the commonalities into other classes
- REFACTOR: There's going to be a fair number of data source lists in routes so.. - REFACTOR: There's going to be a fair number of data source lists in routes so..
- NOT immediate issue, but once the lists are working...
- Do I make a route for each one or user provides a key of which list they want and that goes into a single route to return the data? - Do I make a route for each one or user provides a key of which list they want and that goes into a single route to return the data?
- What about when there are dozens of reports, do they all hang off each object type controller or is there just a central data list route for all combined? - What about when there are dozens of reports, do they all hang off each object type controller or is there just a central data list route for all combined?
- i.e. if I want to make a widget->user->Email report and a separate user email report are they each in widget and user - i.e. if I want to make a widget->user->Email report and a separate user email report are they each in widget and user
- Or, because they are read only lists used for many things do they just go into a central route for read only lists? - Or, because they are read only lists used for many things do they just go into a central route for read only lists?
- I LIKE CENTRAL BECAUSE IT"S TASK ORIENTED and will mean the object controllers can focus on CRUD stuff
- Also rights issues might affect this..? - Also rights issues might affect this..?
- MAYBE it should be a single class object per list with defined properties based on an abstract LIST_DEFINITION class
- Can store rights, field names, sql from etc etc, making the actual list route code maybe into a single controller and single route working off keyed names
- Then they can all go in a single folder for all report lists etc and can just crank out more as required over the years
- With a single class that contains only the names of the keys for fetching with descriptions and object types etc so can fetch by object type or whatever
- One central route with keys would simplify the client end UI certainly - One central route with keys would simplify the client end UI certainly
- Maybe all WidgetController routes are only for CRUD (and mass change) ops and not for list retrieval? - Maybe all WidgetController routes are only for CRUD (and mass change) ops and not for list retrieval?
- Would simplify the WidgetController and biz for sure - Would simplify the WidgetController and biz for sure

View File

@@ -84,31 +84,32 @@ namespace AyaNova.Api.Controllers
} }
/// <summary> //COMMENTED OUT, FOR NOW UNTIL I GET THE FULLY WORKING TEST LIST BELOW THEN COME BACK AND LOOK AT THIS
/// Get list for selection / viewing // /// <summary>
/// // /// Get list for selection / viewing
/// Required roles: Any (some roles might have restrictions on exact fields that are returned) // ///
/// // /// Required roles: Any (some roles might have restrictions on exact fields that are returned)
/// </summary> // ///
/// <param name="pagingOptions">Paging, filtering and sorting options</param> // /// </summary>
/// <returns>Collection with paging data</returns> // /// <param name="pagingOptions">Paging, filtering and sorting options</param>
[HttpGet("List", Name = nameof(List))] // /// <returns>Collection with paging data</returns>
public ActionResult List([FromQuery] ListOptions pagingOptions) // [HttpGet("List", Name = nameof(List))]
{ // public ActionResult List([FromQuery] ListOptions pagingOptions)
if (serverState.IsClosed) // {
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); // if (serverState.IsClosed)
// return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
if (!ModelState.IsValid) // if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); // return BadRequest(new ApiErrorResponse(ModelState));
//Instantiate the business object handler // //Instantiate the business object handler
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); // WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
ApiPagedResponse pr = biz.GetList(Url, nameof(List), pagingOptions).Result; // ApiPagedResponse pr = biz.GetList(Url, nameof(List), pagingOptions).Result;
return Ok(new ApiOkWithPagingResponse(pr)); // return Ok(new ApiOkWithPagingResponse(pr));
// string ret= biz.GetList(Url, nameof(List), pagingOptions).Result; // // string ret= biz.GetList(Url, nameof(List), pagingOptions).Result;
// return Ok(ret); // // return Ok(ret);
} // }
/// <summary> /// <summary>
/// TEST list with relationships /// TEST list with relationships

View File

@@ -272,135 +272,137 @@ namespace AyaNova.Biz
//Generic list of widgets //Generic list of widgets
#region GetList #region GetList
internal async Task<ApiPagedResponse> GetList(IUrlHelper Url, string routeName, ListOptions listOptions) //COMMENTED OUT, FOR NOW UNTIL I GET THE FULLY WORKING TEST LIST BELOW THEN COME BACK AND LOOK AT THIS
{ // internal async Task<ApiPagedResponse> GetList(IUrlHelper Url, string routeName, ListOptions listOptions)
// {
//TODO: Get template (MOCKED FOR NOW UNTIL PROOF OF CONCEPT) // //TODO: Get template (MOCKED FOR NOW UNTIL PROOF OF CONCEPT)
var MOCK_WIDGET_DISPLAY_TEMPLATE_JSON = @" // var MOCK_WIDGET_DISPLAY_TEMPLATE_JSON = @"
{ // {
""full"":[""widgetname"",""widgetserial"",""widgetdollaramount"",""widgetroles"",""widgetstartdate"",""active""], // ""full"":[""widgetname"",""widgetserial"",""widgetdollaramount"",""widgetroles"",""widgetstartdate"",""active""],
""mini"":[""widgetname"",""widgetserial""] // ""mini"":[""widgetname"",""widgetserial""]
} // }
"; // ";
//BUILD THE QUERY // //BUILD THE QUERY
//SELECT FRAGMENT COLUMNS FROM TEMPLATE // //SELECT FRAGMENT COLUMNS FROM TEMPLATE
//"select clm,clm,clm" // //"select clm,clm,clm"
var qSelectColumns = SqlSelectBuilder.Build(AyaObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON, listOptions.Mini); // var qSelectColumns = SqlSelectBuilder.Build(AyaObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON, listOptions.Mini);
var qFrom = "FROM AWIDGET"; // var qFrom = "FROM AWIDGET";
//FILTERED? // //FILTERED?
DataFilter TheFilter = null; // DataFilter TheFilter = null;
if (listOptions.DataFilterId > 0) // if (listOptions.DataFilterId > 0)
{ // {
TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId); // TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId);
} // }
//WHERE CLAUSE - FILTER // //WHERE CLAUSE - FILTER
var qWhere = string.Empty; // var qWhere = string.Empty;
if (listOptions.DataFilterId > 0) // if (listOptions.DataFilterId > 0)
{ // {
qWhere = SqlFilterCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, AyaObjectFields.ObjectFieldsList(AyaObjectFields.WIDGET_KEY), UserId); // qWhere = SqlFilterCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, AyaObjectFields.ObjectFieldsList(AyaObjectFields.WIDGET_KEY), UserId);
} // }
//ORDER BY CLAUSE - SORT // //ORDER BY CLAUSE - SORT
var qOrderBy = string.Empty; // var qOrderBy = string.Empty;
if (listOptions.DataFilterId > 0) // if (listOptions.DataFilterId > 0)
{ // {
//BUILD ORDER BY AND APPEND IT // //BUILD ORDER BY AND APPEND IT
qOrderBy = SqlFilterOrderByBuilder.DataFilterToSQLOrderBy(TheFilter); // qOrderBy = SqlFilterOrderByBuilder.DataFilterToSQLOrderBy(TheFilter);
} // }
//LIMIT AND OFFSET CLAUSE - PAGING // //LIMIT AND OFFSET CLAUSE - PAGING
listOptions.Offset = listOptions.Offset ?? ListOptions.DefaultOffset; // listOptions.Offset = listOptions.Offset ?? ListOptions.DefaultOffset;
listOptions.Limit = listOptions.Limit ?? ListOptions.DefaultLimit; // listOptions.Limit = listOptions.Limit ?? ListOptions.DefaultLimit;
var qLimitOffset = $"LIMIT {listOptions.Limit} OFFSET {listOptions.Offset}"; // var qLimitOffset = $"LIMIT {listOptions.Limit} OFFSET {listOptions.Offset}";
//PUT IT ALL TOGETHER // //PUT IT ALL TOGETHER
string qDataQuery = string.Empty; // string qDataQuery = string.Empty;
string qTotalRecordsQuery = string.Empty; // string qTotalRecordsQuery = string.Empty;
if (TheFilter != null) // if (TheFilter != null)
{ // {
qDataQuery = $"{qSelectColumns} {qFrom} {qWhere} {qOrderBy} {qLimitOffset}"; // qDataQuery = $"{qSelectColumns} {qFrom} {qWhere} {qOrderBy} {qLimitOffset}";
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}"; // qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}";
} // }
else // else
{ // {
qDataQuery = $"{qSelectColumns} {qFrom} {qLimitOffset}"; // qDataQuery = $"{qSelectColumns} {qFrom} {qLimitOffset}";
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}"; // qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}";
} // }
//RETURN OBJECTS // //RETURN OBJECTS
List<object[]> items = new List<object[]>(); // List<object[]> items = new List<object[]>();
long totalRecordCount = 0; // long totalRecordCount = 0;
//RUN THE QUERY // //RUN THE QUERY
using (var command = ct.Database.GetDbConnection().CreateCommand()) // using (var command = ct.Database.GetDbConnection().CreateCommand())
{ // {
ct.Database.OpenConnection(); // ct.Database.OpenConnection();
command.CommandText = qDataQuery; // command.CommandText = qDataQuery;
using (var dr = command.ExecuteReader()) // using (var dr = command.ExecuteReader())
{ // {
while (dr.Read()) // while (dr.Read())
{ // {
object[] row = new object[dr.FieldCount]; // object[] row = new object[dr.FieldCount];
dr.GetValues(row); // dr.GetValues(row);
items.Add(row); // items.Add(row);
} // }
} // }
command.CommandText = qTotalRecordsQuery; // command.CommandText = qTotalRecordsQuery;
using (var dr = command.ExecuteReader()) // using (var dr = command.ExecuteReader())
{ // {
if (dr.Read()) // if (dr.Read())
{ // {
totalRecordCount = dr.GetInt64(0); // totalRecordCount = dr.GetInt64(0);
} // }
} // }
} // }
//TODO: Build the return object in a clean format // //TODO: Build the return object in a clean format
//rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]} // //rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]}
//BUILD THE PAGING LINKS PORTION // //BUILD THE PAGING LINKS PORTION
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject(); // var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject();
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT // //BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
string ColumnsJSON = string.Empty; // string ColumnsJSON = string.Empty;
if (listOptions.Mini) // if (listOptions.Mini)
{ // {
ColumnsJSON = AyaObjectFields.GenerateMINIListColumnsJSON(AyaType.Widget); // ColumnsJSON = AyaObjectFields.GenerateMINIListColumnsJSON(AyaType.Widget);
} // }
else // else
{ // {
ColumnsJSON = AyaObjectFields.GenerateListColumnsJSONFromTemplate(AyaType.Widget, AyaObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON); // ColumnsJSON = AyaObjectFields.GenerateListColumnsJSONFromTemplate(AyaType.Widget, AyaObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON);
} // }
//TODO: BUILD THE RETURN LIST OF DATA ITEMS // //TODO: BUILD THE RETURN LIST OF DATA ITEMS
//If mini format all desired columns in order into the single mini return display (and set the only other return field which is ID) // //If mini format all desired columns in order into the single mini return display (and set the only other return field which is ID)
//If wide then format the fields in oder chosen (grid sort and filter template has already done that part above) // //If wide then format the fields in oder chosen (grid sort and filter template has already done that part above)
//TODO: Genericize the above block of building return when it's working as this code needs to be central and optimized as much as possible // //TODO: Genericize the above block of building return when it's working as this code needs to be central and optimized as much as possible
ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks, ColumnsJSON); // ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks, ColumnsJSON);
return pr; // return pr;
} // }
#endregion #endregion
//TEST WIDGET->USER->EMAILADDRESS multi table list //TEST WIDGET->USER->EMAILADDRESS multi table list
//once this is working can replicate at will
#region TestGetWidgetUserEmailList #region TestGetWidgetUserEmailList
internal async Task<ApiPagedResponse> TestGetWidgetUserEmailList(IUrlHelper Url, string routeName, ListOptions listOptions) internal async Task<ApiPagedResponse> TestGetWidgetUserEmailList(IUrlHelper Url, string routeName, ListOptions listOptions)
{ {
@@ -411,7 +413,7 @@ namespace AyaNova.Biz
""mini"":[""widgetname"",""username"",""emailaddress""] ""mini"":[""widgetname"",""username"",""emailaddress""]
} }
"; ";
var AyaObjectFieldsKey=AyaObjectFields.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY; var AyaObjectFieldsKey = AyaObjectFields.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY;
//BUILD THE QUERY //BUILD THE QUERY
/* /*
@@ -495,8 +497,11 @@ namespace AyaNova.Biz
} }
//TODO: Build the return object in a clean format //TODO: Build the return object in a clean format
//THIS FORMAT IS INCORRECT I THINK
//IT SHOULD BE A FULLER OBJECT WITH THE PROPERTYNAME ?!
//rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]} //rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]}
//TODO: BUILD THE RETURN LIST OF DATA ITEMS
//If mini format all desired columns in order into the single mini return display (and set the only other return field which is ID) //If mini format all desired columns in order into the single mini return display (and set the only other return field which is ID)
//If wide then format the fields in order chosen (grid sort and filter template has already done that part above) //If wide then format the fields in order chosen (grid sort and filter template has already done that part above)
@@ -521,7 +526,6 @@ namespace AyaNova.Biz
} }
ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks, ColumnsJSON); ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks, ColumnsJSON);
return pr; return pr;
} }