This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
@@ -109,45 +110,16 @@ namespace AyaNova.Api.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get paged list of widgets
|
||||
/// Get list for selection / viewing
|
||||
///
|
||||
/// Required roles:
|
||||
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
|
||||
/// </summary>
|
||||
/// <returns>Paged collection of widgets with paging data</returns>
|
||||
[HttpGet("ListWidgets", Name = nameof(ListWidgets))]//We MUST have a "Name" defined or we can't get the link for the pagination, non paged urls don't need a name
|
||||
public async Task<IActionResult> ListWidgets([FromQuery] ListOptions pagingOptions)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
ApiPagedResponse<Widget> pr = await biz.GetManyAsync(Url, nameof(ListWidgets), pagingOptions);
|
||||
return Ok(new ApiOkWithPagingResponse<Widget>(pr));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get pick list
|
||||
///
|
||||
/// Required roles: Any
|
||||
/// Required roles: Any (some roles might have restrictions on exact fields that are returned)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pagingOptions">Paging, filtering and sorting options</param>
|
||||
/// <returns>Paged id/name collection with paging data</returns>
|
||||
[HttpGet("PickList", Name = nameof(WidgetPickList))]
|
||||
public ActionResult WidgetPickList([FromQuery] ListOptions pagingOptions)
|
||||
/// <returns>Collection with paging data</returns>
|
||||
[HttpGet("List", Name = nameof(WidgetList))]
|
||||
public ActionResult WidgetList([FromQuery] ListOptions pagingOptions)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
@@ -158,11 +130,66 @@ namespace AyaNova.Api.Controllers
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
ApiPagedResponse<NameIdItem> pr = biz.GetPickList(Url, nameof(WidgetPickList), pagingOptions);
|
||||
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
||||
// ApiPagedResponse<NameIdItem> pr = biz.GetList(Url, nameof(WidgetList), pagingOptions);
|
||||
// return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
||||
JObject j = biz.GetList(Url, nameof(WidgetList), pagingOptions).Result;
|
||||
return Ok(j);
|
||||
}
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Get paged list of widgets
|
||||
// ///
|
||||
// /// Required roles:
|
||||
// /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
|
||||
// /// </summary>
|
||||
// /// <returns>Paged collection of widgets with paging data</returns>
|
||||
// [HttpGet("ListWidgets", Name = nameof(ListWidgets))]//We MUST have a "Name" defined or we can't get the link for the pagination, non paged urls don't need a name
|
||||
// public async Task<IActionResult> ListWidgets([FromQuery] ListOptions pagingOptions)
|
||||
// {
|
||||
// if (serverState.IsClosed)
|
||||
// return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
|
||||
// //Instantiate the business object handler
|
||||
// WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
// if (!ModelState.IsValid)
|
||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
// ApiPagedResponse<Widget> pr = await biz.GetManyAsync(Url, nameof(ListWidgets), pagingOptions);
|
||||
// return Ok(new ApiOkWithPagingResponse<Widget>(pr));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Get pick list
|
||||
// ///
|
||||
// /// Required roles: Any
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="pagingOptions">Paging, filtering and sorting options</param>
|
||||
// /// <returns>Paged id/name collection with paging data</returns>
|
||||
// [HttpGet("PickList", Name = nameof(WidgetPickList))]
|
||||
// public ActionResult WidgetPickList([FromQuery] ListOptions pagingOptions)
|
||||
// {
|
||||
// if (serverState.IsClosed)
|
||||
// return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
|
||||
// if (!ModelState.IsValid)
|
||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
// //Instantiate the business object handler
|
||||
// WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// ApiPagedResponse<NameIdItem> pr = biz.GetPickList(Url, nameof(WidgetPickList), pagingOptions);
|
||||
// return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
||||
// }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Put (update) widget
|
||||
///
|
||||
@@ -287,9 +314,9 @@ namespace AyaNova.Api.Controllers
|
||||
Widget o = await biz.CreateAsync(inObj);
|
||||
if (o == null)
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
else
|
||||
else
|
||||
return CreatedAtAction(nameof(WidgetController.GetWidget), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using EnumsNET;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
@@ -287,8 +288,9 @@ namespace AyaNova.Biz
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
//get many (paged)
|
||||
internal async Task<ApiPagedResponse<Widget>> GetManyAsync(IUrlHelper Url, string routeName, ListOptions pagingOptions)
|
||||
internal async Task<JObject> GetList(IUrlHelper Url, string routeName, ListOptions pagingOptions)
|
||||
{
|
||||
pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset;
|
||||
pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit;
|
||||
@@ -332,27 +334,86 @@ namespace AyaNova.Biz
|
||||
|
||||
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject();
|
||||
|
||||
ApiPagedResponse<Widget> pr = new ApiPagedResponse<Widget>(items, pageLinks);
|
||||
return pr;
|
||||
|
||||
//TODO: BUILD THE RETURN BASED ON TEMPLATE, ListOpti
|
||||
|
||||
//New return code
|
||||
dynamic ret = new JObject();
|
||||
ret.items = items;
|
||||
ret.pageLinks = pageLinks;
|
||||
|
||||
return ret;
|
||||
// ApiPagedResponse<Widget> pr = new ApiPagedResponse<Widget>(items, pageLinks);
|
||||
// return pr;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get PickList
|
||||
/// </summary>
|
||||
/// <param name="Url"></param>
|
||||
/// <param name="routeName"></param>
|
||||
/// <param name="pagingOptions"></param>
|
||||
/// <returns></returns>
|
||||
internal ApiPagedResponse<NameIdItem> GetPickList(IUrlHelper Url, string routeName, ListOptions pagingOptions)
|
||||
{
|
||||
pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset;
|
||||
pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit;
|
||||
var ret = PickListFetcher.GetPickList(ct, UserId, pagingOptions, FilterOptions(), "awidget");
|
||||
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, ret.TotalRecordCount).PagingLinksObject();
|
||||
ApiPagedResponse<NameIdItem> pr = new ApiPagedResponse<NameIdItem>(ret.Items, pageLinks);
|
||||
return pr;
|
||||
}
|
||||
// //get many (paged)
|
||||
// internal async Task<ApiPagedResponse<Widget>> GetManyAsync(IUrlHelper Url, string routeName, ListOptions pagingOptions)
|
||||
// {
|
||||
// pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset;
|
||||
// pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit;
|
||||
|
||||
// //BUILD THE QUERY
|
||||
// //base query
|
||||
// var q = "SELECT *, xmin FROM AWIDGET ";
|
||||
|
||||
// //GET THE FILTER / SORT
|
||||
// if (pagingOptions.DataFilterId > 0)
|
||||
// {
|
||||
// var TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == pagingOptions.DataFilterId);
|
||||
|
||||
// //BUILD WHERE AND APPEND IT
|
||||
// q = q + FilterSqlCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, WidgetBiz.FilterOptions(), UserId);
|
||||
|
||||
// //BUILD ORDER BY AND APPEND IT
|
||||
// q = q + FilterSqlOrderByBuilder.DataFilterToSQLOrderBy(TheFilter);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //GET DEFAULT ORDER BY
|
||||
// q = q + FilterSqlOrderByBuilder.DefaultGetManyOrderBy();
|
||||
// }
|
||||
|
||||
|
||||
// #pragma warning disable EF1000
|
||||
|
||||
// var items = await ct.Widget
|
||||
// .FromSqlRaw(q)
|
||||
// .AsNoTracking()
|
||||
// .Skip(pagingOptions.Offset.Value)
|
||||
// .Take(pagingOptions.Limit.Value)
|
||||
// .ToArrayAsync();
|
||||
|
||||
// var totalRecordCount = await ct.Widget
|
||||
// .FromSqlRaw(q)
|
||||
// .AsNoTracking()
|
||||
// .CountAsync();
|
||||
// #pragma warning restore EF1000
|
||||
|
||||
// var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject();
|
||||
|
||||
// ApiPagedResponse<Widget> pr = new ApiPagedResponse<Widget>(items, pageLinks);
|
||||
// return pr;
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Get PickList
|
||||
// /// </summary>
|
||||
// /// <param name="Url"></param>
|
||||
// /// <param name="routeName"></param>
|
||||
// /// <param name="pagingOptions"></param>
|
||||
// /// <returns></returns>
|
||||
// internal ApiPagedResponse<NameIdItem> GetPickList(IUrlHelper Url, string routeName, ListOptions pagingOptions)
|
||||
// {
|
||||
// pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset;
|
||||
// pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit;
|
||||
// var ret = PickListFetcher.GetPickList(ct, UserId, pagingOptions, FilterOptions(), "awidget");
|
||||
// var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, ret.TotalRecordCount).PagingLinksObject();
|
||||
// ApiPagedResponse<NameIdItem> pr = new ApiPagedResponse<NameIdItem>(ret.Items, pageLinks);
|
||||
// return pr;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user