This commit is contained in:
2019-04-30 19:41:00 +00:00
parent 0be48bebb3
commit ae791ec366
20 changed files with 63 additions and 55 deletions

View File

@@ -3,17 +3,25 @@ namespace AyaNova.Api.ControllerHelpers
{ {
//return the response with optional readonly flag
public class ApiOkResponse //this exists basically for consistency and to reduce the bandwidth if not readonly which is most common
public static class ApiOkResponse
{ {
public static object Response(object result, bool isReadOnly)
public object Data { get; }
public bool ReadOnly {get;}
public ApiOkResponse(object result, bool isReadOnly)
{ {
Data = result; if (isReadOnly)
ReadOnly=isReadOnly; {
return new
{
Data = result,
ReadOnly = true
};
}
else
{
return new { Data = result };
}
} }
}//eoc }//eoc

View File

@@ -104,7 +104,7 @@ namespace AyaNova.Api.Controllers
log.LogInformation("Auth retry dlkey"); log.LogInformation("Auth retry dlkey");
}; };
return Ok(new ApiOkResponse(new { dlkey = u.DlKey, expires = u.DlKeyExpire }, true)); return Ok(ApiOkResponse.Response(new { dlkey = u.DlKey, expires = u.DlKeyExpire }, true));
} }
} }
@@ -247,7 +247,7 @@ namespace AyaNova.Api.Controllers
} }
//Return the list of attachment ids and filenames //Return the list of attachment ids and filenames
return Ok(new ApiOkResponse(returnList, false)); return Ok(ApiOkResponse.Response(returnList, false));
} }
/// <summary> /// <summary>

View File

@@ -136,7 +136,7 @@ namespace AyaNova.Api.Controllers
} }
return Ok(new ApiOkResponse(new return Ok(ApiOkResponse.Response(new
{ {
token = TestToken token = TestToken
}, true)); }, true));
@@ -210,7 +210,7 @@ namespace AyaNova.Api.Controllers
//TODO: This needs to return the authorization roles of the user in the payload and it should all be in the token //TODO: This needs to return the authorization roles of the user in the payload and it should all be in the token
//and remove the issued, expires id etc so that all that is returned is an encoded token with that info in it //and remove the issued, expires id etc so that all that is returned is an encoded token with that info in it
return Ok(new ApiOkResponse(new return Ok(ApiOkResponse.Response(new
{ {
// ok = 1, // ok = 1,
// issued = iat, // issued = iat,

View File

@@ -129,7 +129,7 @@ namespace AyaNova.Api.Controllers
} }
return Ok(new ApiOkResponse(ReturnList, true)); return Ok(ApiOkResponse.Response(ReturnList, true));
} }
@@ -154,7 +154,7 @@ namespace AyaNova.Api.Controllers
ret.Add(new KeyValuePair<string, string>("authorizationroles", "AyaNova user account role types")); ret.Add(new KeyValuePair<string, string>("authorizationroles", "AyaNova user account role types"));
ret.Add(new KeyValuePair<string, string>("AyaType", "All AyaNova object types, use the AyaTypeController route to fetch these")); ret.Add(new KeyValuePair<string, string>("AyaType", "All AyaNova object types, use the AyaTypeController route to fetch these"));
return Ok(new ApiOkResponse(ret, true)); return Ok(ApiOkResponse.Response(ret, true));
} }

View File

@@ -70,7 +70,7 @@ namespace AyaNova.Api.Controllers
} }
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }

View File

@@ -71,7 +71,7 @@ namespace AyaNova.Api.Controllers
if (o == null) if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(new ApiOkResponse(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType))); return Ok(ApiOkResponse.Response(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType)));
} }
@@ -96,7 +96,7 @@ namespace AyaNova.Api.Controllers
DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext); DataFilterBiz biz = DataFilterBiz.GetBiz(ct, HttpContext);
var l = await biz.GetPickListAsync(ListKey); var l = await biz.GetPickListAsync(ListKey);
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }
@@ -142,7 +142,7 @@ namespace AyaNova.Api.Controllers
else else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }

View File

@@ -67,7 +67,7 @@ namespace AyaNova.Api.Controllers
} }
var result = await EventLogProcessor.GetLogForObject(opt, ct); var result = await EventLogProcessor.GetLogForObject(opt, ct);
return Ok(new ApiOkResponse(result, true)); return Ok(ApiOkResponse.Response(result, true));
} }
@@ -104,7 +104,7 @@ namespace AyaNova.Api.Controllers
var result = await EventLogProcessor.GetLogForUser(opt, ct); var result = await EventLogProcessor.GetLogForUser(opt, ct);
return Ok(new ApiOkResponse(result, true)); return Ok(ApiOkResponse.Response(result, true));
} }

View File

@@ -87,7 +87,7 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType))); return Ok(ApiOkResponse.Response(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType)));
} }
@@ -117,7 +117,7 @@ namespace AyaNova.Api.Controllers
if (FormAvailableFields.IsValidFormKey(formkey)) if (FormAvailableFields.IsValidFormKey(formkey))
{ {
return Ok(new ApiOkResponse(FormAvailableFields.FormFields(formkey), true)); return Ok(ApiOkResponse.Response(FormAvailableFields.FormFields(formkey), true));
} }
else else
{ {
@@ -145,7 +145,7 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
return Ok(new ApiOkResponse(AyDataType.ValidCustomFieldTypes, true)); return Ok(ApiOkResponse.Response(AyDataType.ValidCustomFieldTypes, true));
} }
@@ -169,7 +169,7 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
return Ok(new ApiOkResponse(FormAvailableFields.AvailableFormKeys, true)); return Ok(ApiOkResponse.Response(FormAvailableFields.AvailableFormKeys, true));
} }
@@ -215,7 +215,7 @@ namespace AyaNova.Api.Controllers
else else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }

View File

@@ -138,7 +138,7 @@ namespace AyaNova.Api.Controllers
} }
//Return the list of attachment ids and filenames //Return the list of attachment ids and filenames
return Ok(new ApiOkResponse(returnList, true)); return Ok(ApiOkResponse.Response(returnList, true));
} }
@@ -204,7 +204,7 @@ namespace AyaNova.Api.Controllers
//dump file name example: ayanova.data.dump.XXX.zip //dump file name example: ayanova.data.dump.XXX.zip
List<string> l = FileUtil.UtilityFileList("ayanova.data.dump.*.zip"); List<string> l = FileUtil.UtilityFileList("ayanova.data.dump.*.zip");
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }

View File

@@ -77,7 +77,7 @@ namespace AyaNova.Api.Controllers
JobOperationsBiz biz = new JobOperationsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); JobOperationsBiz biz = new JobOperationsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
List<JobOperationsFetchInfo> l = await biz.GetJobListAsync(); List<JobOperationsFetchInfo> l = await biz.GetJobListAsync();
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }
@@ -116,7 +116,7 @@ namespace AyaNova.Api.Controllers
JobOperationsBiz biz = new JobOperationsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); JobOperationsBiz biz = new JobOperationsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
List<JobOperationsLogInfoItem> l = await biz.GetJobLogListAsync(gid); List<JobOperationsLogInfoItem> l = await biz.GetJobLogListAsync(gid);
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }

View File

@@ -67,7 +67,7 @@ namespace AyaNova.Api.Controllers
var ret = AyaNova.Core.License.LicenseInfoAsJson; var ret = AyaNova.Core.License.LicenseInfoAsJson;
return Ok(new ApiOkResponse(ret, true)); return Ok(ApiOkResponse.Response(ret, true));
} }
@@ -129,7 +129,7 @@ namespace AyaNova.Api.Controllers
//Log //Log
EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct); EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
return Ok(new ApiOkResponse(ret, true)); return Ok(ApiOkResponse.Response(ret, true));
} }
@@ -181,7 +181,7 @@ namespace AyaNova.Api.Controllers
//Log //Log
EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct); EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
return Ok(new ApiOkResponse(ret, true)); return Ok(ApiOkResponse.Response(ret, true));
} }
//------------------------------------------------------ //------------------------------------------------------

View File

@@ -82,7 +82,7 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
return Ok(new ApiOkResponse(o, true)); return Ok(ApiOkResponse.Response(o, true));
} }
@@ -106,7 +106,7 @@ namespace AyaNova.Api.Controllers
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
var l = await biz.GetPickListAsync(); var l = await biz.GetPickListAsync();
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }
@@ -130,7 +130,7 @@ namespace AyaNova.Api.Controllers
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
var l = biz.LocaleKeyCoverage(); var l = biz.LocaleKeyCoverage();
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }
#endif #endif
@@ -157,7 +157,7 @@ namespace AyaNova.Api.Controllers
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
var l = await biz.GetSubset(inObj); var l = await biz.GetSubset(inObj);
return Ok(new ApiOkResponse(l, true)); return Ok(ApiOkResponse.Response(l, true));
} }
@@ -265,7 +265,7 @@ namespace AyaNova.Api.Controllers
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true));
} }
/// <summary> /// <summary>
@@ -331,7 +331,7 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true));
} }

View File

@@ -135,7 +135,7 @@ namespace AyaNova.Api.Controllers
return Ok(new ApiOkResponse(o, true)); return Ok(ApiOkResponse.Response(o, true));
} }

View File

@@ -101,7 +101,7 @@ namespace AyaNova.Api.Controllers
//Log //Log
EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct); EventLogProcessor.LogEventToDatabase(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
return Ok(new ApiOkResponse(json, true)); return Ok(ApiOkResponse.Response(json, true));
} }
/// <summary> /// <summary>

View File

@@ -70,7 +70,7 @@ namespace AyaNova.Api.Controllers
//Do the search //Do the search
var SearchResults = await Search.DoSearch(ct, UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), searchParams); var SearchResults = await Search.DoSearch(ct, UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), searchParams);
return Ok(new ApiOkResponse(SearchResults, true)); return Ok(ApiOkResponse.Response(SearchResults, true));
} }

View File

@@ -48,7 +48,7 @@ namespace AyaNova.Api.Controllers
[HttpGet] [HttpGet]
public ActionResult Get() public ActionResult Get()
{ {
return Ok(new ApiOkResponse(new ServerStateModel() { ServerState = serverState.GetState().ToString(), Reason = serverState.Reason }, true)); return Ok(ApiOkResponse.Response(new ServerStateModel() { ServerState = serverState.GetState().ToString(), Reason = serverState.Reason }, true));
} }

View File

@@ -55,7 +55,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
} }
return Ok(new ApiOkResponse(TagUtil.PickListFiltered(ct, query),true)); return Ok(ApiOkResponse.Response(TagUtil.PickListFiltered(ct, query),true));
} }
@@ -75,7 +75,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
} }
return Ok(new ApiOkResponse(TagUtil.CloudListFiltered(ct, query), true)); return Ok(ApiOkResponse.Response(TagUtil.CloudListFiltered(ct, query), true));
} }
@@ -99,7 +99,7 @@ namespace AyaNova.Api.Controllers
// ret.Add(new KeyValuePair<string, string>("authorizationroles", "AyaNova user account role types")); // ret.Add(new KeyValuePair<string, string>("authorizationroles", "AyaNova user account role types"));
// ret.Add(new KeyValuePair<string, string>("AyaType", "All AyaNova object types, use the AyaTypeController route to fetch these")); // ret.Add(new KeyValuePair<string, string>("AyaType", "All AyaNova object types, use the AyaTypeController route to fetch these"));
// return Ok(new ApiOkResponse(ret)); // return Ok(ApiOkResponse.Response(ret));
// } // }

View File

@@ -83,7 +83,7 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
return Ok(new ApiOkResponse(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType))); return Ok(ApiOkResponse.Response(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType)));
} }
@@ -240,7 +240,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }
@@ -303,7 +303,7 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }

View File

@@ -83,7 +83,7 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
return Ok(new ApiOkResponse(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType))); return Ok(ApiOkResponse.Response(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType)));
} }
@@ -148,7 +148,7 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }
@@ -215,7 +215,7 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }

View File

@@ -74,7 +74,7 @@ namespace AyaNova.Api.Controllers
if (o == null) if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(new ApiOkResponse(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType))); return Ok(ApiOkResponse.Response(o, !Authorized.IsAuthorizedToModify(HttpContext.Items, biz.BizType)));
} }
@@ -200,7 +200,7 @@ namespace AyaNova.Api.Controllers
else else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }
@@ -250,7 +250,7 @@ namespace AyaNova.Api.Controllers
else else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }, true)); return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
} }