This commit is contained in:
2020-01-22 00:19:38 +00:00
parent 88d66cea1d
commit 8de0c922cd
5 changed files with 40 additions and 36 deletions

View File

@@ -14,6 +14,7 @@ Clean up AyaObjectField definition for FORM FIELD STUFF:
Extracted from ayaobjectfielddefinitions
Essentially the same thing as it is now, so maybe just rename the existing one
Rename objectfieldscontroller / routes
MAKE DATALIST ROUTE FOR FETCHING LISTS BY KEY
- REMOVE LISTS FROM INDIVIDUAL OBJECT ROUTES AS MUCH AS POSSIBLE

View File

@@ -24,10 +24,10 @@ namespace AyaNova.Api.Controllers
[Route("api/v{version:apiVersion}/[controller]")]
[Produces("application/json")]
[Authorize]
public class DataFilterController : ControllerBase
public class DataListFilterController : ControllerBase
{
private readonly AyContext ct;
private readonly ILogger<DataFilterController> log;
private readonly ILogger<DataListFilterController> log;
private readonly ApiServerState serverState;
@@ -37,7 +37,7 @@ namespace AyaNova.Api.Controllers
/// <param name="dbcontext"></param>
/// <param name="logger"></param>
/// <param name="apiServerState"></param>
public DataFilterController(AyContext dbcontext, ILogger<DataFilterController> logger, ApiServerState apiServerState)
public DataListFilterController(AyContext dbcontext, ILogger<DataListFilterController> logger, ApiServerState apiServerState)
{
ct = dbcontext;
log = logger;
@@ -60,7 +60,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//Instantiate the business object handler
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
DataListFilterBiz biz = DataListFilterBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
@@ -94,7 +94,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//Instantiate the business object handler
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
DataListFilterBiz biz = DataListFilterBiz.GetBiz(ct, HttpContext);
var l = await biz.GetPickListAsync(ListKey);
return Ok(ApiOkResponse.Response(l, true));
@@ -122,7 +122,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//Instantiate the business object handler
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
DataListFilterBiz biz = DataListFilterBiz.GetBiz(ct, HttpContext);
var o = await biz.GetNoLogAsync(id);
if (o == null)
@@ -163,7 +163,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//Instantiate the business object handler
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
DataListFilterBiz biz = DataListFilterBiz.GetBiz(ct, HttpContext);
//If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
@@ -177,7 +177,7 @@ namespace AyaNova.Api.Controllers
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction(nameof(DataFilterController.GetDataFilter), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
return CreatedAtAction(nameof(DataListFilterController.GetDataFilter), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}
@@ -202,7 +202,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//Instantiate the business object handler
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
DataListFilterBiz biz = DataListFilterBiz.GetBiz(ct, HttpContext);
var o = await biz.GetNoLogAsync(id);
if (o == null)

View File

@@ -121,16 +121,16 @@ namespace AyaNova.Biz
}
// public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName)
// {
// var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace(
// lTCustomFieldName, // Our input
// "[^0-9]", // Select everything that is not in the range of 0-9
// "" // Replace that with an empty string.
// ));
public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName)
{
var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace(
lTCustomFieldName, // Our input
"[^0-9]", // Select everything that is not in the range of 0-9
"" // Replace that with an empty string.
));
// return $"c{i}";
// }
return $"c{i}";
}

View File

@@ -36,7 +36,7 @@ namespace AyaNova.Biz
case AyaType.Locale:
return new LocaleBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
case AyaType.DataFilter:
return new DataFilterBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
return new DataListFilterBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
case AyaType.FormCustom:
return new FormCustomBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);

View File

@@ -6,16 +6,17 @@ using Newtonsoft.Json.Linq;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Models;
using AyaNova.DataList;
namespace AyaNova.Biz
{
internal class DataFilterBiz : BizObject
internal class DataListFilterBiz : BizObject
{
internal DataFilterBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
internal DataListFilterBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
{
ct = dbcontext;
UserId = currentUserId;
@@ -24,15 +25,15 @@ namespace AyaNova.Biz
BizType = AyaType.DataFilter;
}
internal static DataFilterBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
internal static DataListFilterBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
{
return new DataFilterBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
return new DataListFilterBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
}
//Version for internal use
internal static DataFilterBiz GetBizInternal(AyContext ct)
internal static DataListFilterBiz GetBizInternal(AyContext ct)
{
return new DataFilterBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
return new DataListFilterBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
}
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -247,15 +248,17 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListKey");
List<AyaFormFieldDefinition> FieldList = null;
if (!AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(inObj.ListKey))
var DataList = DataListFactory.GetAyaDataList(inObj.ListKey);
// List<AyaDataListFieldDefinition> FieldList = null;
//if (!AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(inObj.ListKey))
if (DataList == null)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" is empty or in-valid");
}
else
{
FieldList = AyaFormFieldDefinitions.AyaObjectFields(inObj.ListKey);
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" DataListKey is not valid");
}
// else
// {
// FieldList = AyaDataListFieldDefinition.AyaObjectFields(inObj.ListKey);
// }
if (inObj.ListKey.Length > 255)
@@ -279,10 +282,10 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, \"fld\" property is empty and required");
//validate the field name if we can
if (FieldList != null)
if (DataList != null)
{
var TheField = FieldList.SingleOrDefault(x => x.FieldKey.ToLowerInvariant() == fld);
var TheField = DataList.FieldDefinitions.SingleOrDefault(x => x.FieldKey.ToLowerInvariant() == fld);
if (TheField == null)
{
@@ -348,10 +351,10 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, \"fld\" property is empty and required");
//validate the field name if we can
if (FieldList != null)
if (DataList != null)
{
if (!FieldList.Exists(x => x.FieldKey.ToLowerInvariant() == fld && x.IsFilterable))
if (!DataList.FieldDefinitions.Exists(x => x.FieldKey.ToLowerInvariant() == fld && x.IsFilterable))
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
}