This commit is contained in:
213
server/AyaNova/Controllers/DataListController.cs
Normal file
213
server/AyaNova/Controllers/DataListController.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.DataList;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class DataListController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AyaTypeController> log;
|
||||
private readonly ApiServerState serverState;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="dbcontext"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="apiServerState"></param>
|
||||
public DataListController(AyContext dbcontext, ILogger<AyaTypeController> logger, ApiServerState apiServerState)
|
||||
{
|
||||
ct = dbcontext;
|
||||
log = logger;
|
||||
serverState = apiServerState;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get list of data for selection / viewing
|
||||
///
|
||||
/// Required roles: Varies by list
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="listOptions">List key, Paging, filtering and sorting options</param>
|
||||
/// <returns>Collection with paging data</returns>
|
||||
[HttpGet("List", Name = nameof(List))]
|
||||
public async Task<IActionResult> List([FromQuery] ListOptions listOptions)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var MOCK_WIDGET_DISPLAY_TEMPLATE_JSON = @"
|
||||
{
|
||||
""full"":[""widgetname"",""widgetserial"",""widgetdollaramount"",""widgetroles"",""widgetstartdate"",""widgetactive"",""username""],
|
||||
""mini"":[""widgetname"",""widgetserial""]
|
||||
}
|
||||
";
|
||||
ApiPagedResponse pr = await DataListFetcher.GetResponse(nameof(WidgetDataList), ct, Url, routeName, listOptions, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON, UserId);
|
||||
|
||||
|
||||
// ApiPagedResponse pr = biz.GetList(Url, nameof(List), listOptions).Result;
|
||||
return Ok(new ApiOkWithPagingResponse(pr));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of all DataList keys available
|
||||
///
|
||||
/// Required roles: Any
|
||||
/// </summary>
|
||||
/// <returns>List of strings</returns>
|
||||
[HttpGet("ListKeys")]
|
||||
public ActionResult GetDataListKeys([FromRoute]string enumkey)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
long LocaleId = UserLocaleIdFromContext.Id(HttpContext.Items);
|
||||
List<string> LocaleKeysToFetch = new List<string>();
|
||||
|
||||
List<NameIdItem> ReturnList = new List<NameIdItem>();
|
||||
|
||||
switch (enumkey)
|
||||
{
|
||||
case "datatypes":
|
||||
{
|
||||
//Iterate the enum and get the values
|
||||
Type t = typeof(AyaUiFieldDataType);
|
||||
Enum.GetName(t, AyaUiFieldDataType.NoType);
|
||||
foreach (var dt in Enum.GetValues(t))
|
||||
{
|
||||
ReturnList.Add(new NameIdItem() { Name = Enum.GetName(t, dt), Id = (int)dt });
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case "usertypes":
|
||||
{
|
||||
LocaleKeysToFetch.Add("UserTypesAdministrator");
|
||||
LocaleKeysToFetch.Add("UserTypesSchedulable");
|
||||
LocaleKeysToFetch.Add("UserTypesNonSchedulable");
|
||||
LocaleKeysToFetch.Add("UserTypesClient");
|
||||
LocaleKeysToFetch.Add("UserTypesHeadOffice");
|
||||
LocaleKeysToFetch.Add("UserTypesSubContractor");
|
||||
var LT = LocaleBiz.GetSubsetStatic(LocaleKeysToFetch, LocaleId).Result;
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesAdministrator"], Id = (long)UserType.Administrator });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesSchedulable"], Id = (long)UserType.Schedulable });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesNonSchedulable"], Id = (long)UserType.NonSchedulable });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesClient"], Id = (long)UserType.Client });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesHeadOffice"], Id = (long)UserType.HeadOffice });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesSubContractor"], Id = (long)UserType.Subcontractor });
|
||||
}
|
||||
break;
|
||||
|
||||
case "authorizationroles":
|
||||
{
|
||||
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleNoRole");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleBizAdminLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleBizAdminFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleDispatchLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleDispatchFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleInventoryLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleInventoryFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleAccountingFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleTechLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleTechFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSubContractorLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSubContractorFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleClientLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleClientFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleOpsAdminLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleOpsAdminFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSalesLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSalesFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleAll");
|
||||
var LT = LocaleBiz.GetSubsetStatic(LocaleKeysToFetch, LocaleId).Result;
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleNoRole"], Id = (long)AuthorizationRoles.NoRole });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleBizAdminLimited"], Id = (long)AuthorizationRoles.BizAdminLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleBizAdminFull"], Id = (long)AuthorizationRoles.BizAdminFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleDispatchLimited"], Id = (long)AuthorizationRoles.DispatchLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleDispatchFull"], Id = (long)AuthorizationRoles.DispatchFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleInventoryLimited"], Id = (long)AuthorizationRoles.InventoryLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleInventoryFull"], Id = (long)AuthorizationRoles.InventoryFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleAccountingFull"], Id = (long)AuthorizationRoles.AccountingFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleTechLimited"], Id = (long)AuthorizationRoles.TechLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleTechFull"], Id = (long)AuthorizationRoles.TechFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleSubContractorLimited"], Id = (long)AuthorizationRoles.SubContractorLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleSubContractorFull"], Id = (long)AuthorizationRoles.SubContractorFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleClientLimited"], Id = (long)AuthorizationRoles.ClientLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleClientFull"], Id = (long)AuthorizationRoles.ClientFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleOpsAdminLimited"], Id = (long)AuthorizationRoles.OpsAdminLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleOpsAdminFull"], Id = (long)AuthorizationRoles.OpsAdminFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleSalesLimited"], Id = (long)AuthorizationRoles.SalesLimited });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleSalesFull"], Id = (long)AuthorizationRoles.SalesFull });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleAll"], Id = (long)AuthorizationRoles.All });
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ReturnList.Add(new NameIdItem() { Name = $"Unknown enum type list key value {enumkey}", Id = (long)UserType.Administrator });
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return Ok(ApiOkResponse.Response(ReturnList, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all possible enumerated values picklist key names
|
||||
///
|
||||
/// Required roles: Any
|
||||
/// </summary>
|
||||
/// <returns>List of AyaNova enumerated type list key names that can be fetched from the AyaEnumPickList/GetPickListRoute</returns>
|
||||
[HttpGet("listkeys")]
|
||||
public ActionResult GetTypesList()
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
List<KeyValuePair<string, string>> ret = new List<KeyValuePair<string, string>>();
|
||||
ret.Add(new KeyValuePair<string, string>("usertypes", "AyaNova user account 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>("datatypes", "Types of data used in AyaNova for display and formatting UI purposes"));
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
Reference in New Issue
Block a user