This commit is contained in:
@@ -57,6 +57,11 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (serverState.IsClosed)
|
if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
|
|
||||||
|
//Attempt to get the data list by key to see if key is valid and for the default template and valid field names
|
||||||
|
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||||
|
if (DataList == null)
|
||||||
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
var o = await biz.GetAsync(DataListKey);
|
var o = await biz.GetAsync(DataListKey, true, DataList);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
@@ -111,10 +116,15 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
//Attempt to get the data list by key to see if key is valid and for the default template and valid field names
|
||||||
|
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||||
|
if (DataList == null)
|
||||||
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetNoLogAsync(DataListKey);
|
var o = await biz.GetAsync(DataListKey, false, DataList);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
@@ -123,7 +133,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.Put(o, inObj))
|
if (!biz.Put(o, inObj, DataList))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -132,7 +142,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
// else
|
// else
|
||||||
//these always exist so can only be concurrency conflict
|
//these always exist so can only be concurrency conflict
|
||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||||
}
|
}
|
||||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||||
}
|
}
|
||||||
@@ -157,10 +167,15 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
//Attempt to get the data list by key to see if key is valid
|
||||||
|
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||||
|
if (DataList == null)
|
||||||
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetNoLogAsync(DataListKey);
|
var o = await biz.GetAsync(DataListKey, false, DataList);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
//Instantiate list object specified
|
//Instantiate list object specified
|
||||||
//this is safe as it's only attempting to load assemblies in the AyaNova.DataList namespace so can't attempt to instantiate some random object or nefarious object
|
//this is safe as it's only attempting to load assemblies in the AyaNova.DataList namespace so can't attempt to instantiate some random object or nefarious object
|
||||||
|
//returns null if doesn't exist
|
||||||
internal static IAyaDataList GetAyaDataList(string ListKey)
|
internal static IAyaDataList GetAyaDataList(string ListKey)
|
||||||
{
|
{
|
||||||
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
||||||
|
|||||||
@@ -109,26 +109,27 @@ namespace AyaNova.Biz
|
|||||||
/// GET
|
/// GET
|
||||||
|
|
||||||
//Get one
|
//Get one
|
||||||
internal async Task<DataListTemplate> GetAsync(string DataListKey, bool log=true)
|
internal async Task<DataListTemplate> GetAsync(string DataListKey, bool log, IAyaDataList dataList)
|
||||||
{
|
{
|
||||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
//DataListKey always exists, if not in db then in default form
|
||||||
var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId));
|
var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.DataListKey == DataListKey);
|
||||||
if (ret != null)
|
|
||||||
|
if (log)
|
||||||
{
|
{
|
||||||
//Log
|
//Log
|
||||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
EventLogProcessor.LogEventToDatabase(new Event(UserId, ret.Id, BizType, AyaEvent.Retrieved), ct);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// GET
|
// /// GET
|
||||||
internal async Task<DataListTemplate> GetNoLogAsync(long fetchId)
|
// internal async Task<DataListTemplate> GetNoLogAsync(long fetchId)
|
||||||
{
|
// {
|
||||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
// //This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||||
return await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId);
|
// return await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// //get picklist (NOT PAGED)
|
// //get picklist (NOT PAGED)
|
||||||
// internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)
|
// internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user