This commit is contained in:
@@ -41,13 +41,12 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get DataListSavedColumnView
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// Get DataListSavedColumnView for current user
|
||||
/// </summary>
|
||||
/// <param name="listKey"></param>
|
||||
/// <returns>DataListSavedColumnView</returns>
|
||||
[HttpGet("{userId}/{listKey}")]
|
||||
public async Task<IActionResult> GetDataListSavedColumnView([FromRoute] long userId, [FromRoute] string listKey)
|
||||
public async Task<IActionResult> GetDataListSavedColumnView([FromRoute] string listKey)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
@@ -56,7 +55,7 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
var o = await biz.GetAsync(userId, listKey, true);
|
||||
var o = await biz.GetAsync(biz.UserId, listKey, true);
|
||||
if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
return Ok(ApiOkResponse.Response(o));
|
||||
}
|
||||
@@ -89,23 +88,21 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
/// <summary>
|
||||
/// Reset DataListSavedColumnView to factory defaults
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// </summary>
|
||||
/// <param name="listKey"></param>
|
||||
/// <returns>NoContent</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteProject([FromRoute] long userId, [FromRoute] string listKey)
|
||||
public async Task<IActionResult> ResetDataListSavedColumnView([FromRoute] string listKey)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
DataListSavedColumnViewBiz biz = DataListSavedColumnViewBiz.GetBiz(ct, HttpContext);
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!await biz.DeleteAsync(userId, listKey))
|
||||
var o = await biz.DeleteAsync(biz.UserId, listKey);
|
||||
if (o == null)
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
return NoContent();
|
||||
return Ok(ApiOkResponse.Response(o));
|
||||
}
|
||||
|
||||
//------------
|
||||
|
||||
@@ -53,8 +53,13 @@ namespace AyaNova.Biz
|
||||
else
|
||||
{
|
||||
//delete the existing one in favor of this one
|
||||
if (!await DeleteAsync(newObject.UserId, newObject.ListKey))
|
||||
return null;
|
||||
var dbObject = await GetAsync(newObject.UserId, newObject.ListKey, false);
|
||||
if (dbObject != null)
|
||||
{
|
||||
ct.DataListSavedColumnView.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await ct.DataListSavedColumnView.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
@@ -72,17 +77,19 @@ namespace AyaNova.Biz
|
||||
internal async Task<DataListSavedColumnView> GetAsync(long userId, string listKey, bool createDefaultIfNecessary)
|
||||
{
|
||||
var ret = await ct.DataListSavedColumnView.AsNoTracking().SingleOrDefaultAsync(z => z.UserId == userId && z.ListKey == listKey);
|
||||
if(ret==null && createDefaultIfNecessary){
|
||||
if(!DataListFactory.ListKeyIsValid(listKey)){
|
||||
if (ret == null && createDefaultIfNecessary)
|
||||
{
|
||||
if (!DataListFactory.ListKeyIsValid(listKey))
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"ListKey '{listKey}' is not a valid DataListKey");
|
||||
}
|
||||
ret=new DataListSavedColumnView();
|
||||
ret.UserId=UserId;
|
||||
ret.ListKey=listKey;
|
||||
var dataList=DataListFactory.GetAyaDataList(listKey);
|
||||
ret.Columns=JsonConvert.SerializeObject(dataList.DefaultColumns);
|
||||
ret.Sort=JsonConvert.SerializeObject(dataList.DefaultSortBy);
|
||||
return await CreateAsync(ret);
|
||||
ret = new DataListSavedColumnView();
|
||||
ret.UserId = UserId;
|
||||
ret.ListKey = listKey;
|
||||
var dataList = DataListFactory.GetAyaDataList(listKey);
|
||||
ret.Columns = JsonConvert.SerializeObject(dataList.DefaultColumns);
|
||||
ret.Sort = JsonConvert.SerializeObject(dataList.DefaultSortBy);
|
||||
return await CreateAsync(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -90,20 +97,22 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//DELETE (RESET)
|
||||
//
|
||||
internal async Task<bool> DeleteAsync(long userId, string listKey)
|
||||
internal async Task<DataListSavedColumnView> DeleteAsync(long userId, string listKey)
|
||||
{
|
||||
//this is effectively the RESET route handler
|
||||
//so it can be called any time even if there is no default list and it's a-ok
|
||||
//because a new default will be created if needed
|
||||
|
||||
var dbObject = await GetAsync(userId, listKey, false);
|
||||
if (dbObject != null)
|
||||
{
|
||||
ct.DataListSavedColumnView.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
dbObject = await GetAsync(userId, listKey, true);
|
||||
}
|
||||
return true;
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +130,10 @@ namespace AyaNova.Biz
|
||||
if (string.IsNullOrWhiteSpace(inObj.ListKey))
|
||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListKey");
|
||||
|
||||
if (!DataListFactory.ListKeyIsValid(inObj.ListKey))
|
||||
if (!DataListFactory.ListKeyIsValid(inObj.ListKey))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" DataListKey is not valid");
|
||||
|
||||
|
||||
|
||||
|
||||
//Validate Sort JSON
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user