This commit is contained in:
@@ -158,7 +158,25 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Report list for object
|
||||
/// </summary>
|
||||
/// <param name="ayType">Type of object</param>
|
||||
/// <returns>Name / id report list of allowed reports for role of requester</returns>
|
||||
[HttpGet("list/{ayType}")]
|
||||
public async Task<IActionResult> GetReportList([FromRoute] AyaType ayType)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
ReportBiz biz = ReportBiz.GetBiz(ct, HttpContext);
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
var o = await biz.GetReportListAsync(ayType);
|
||||
if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
return Ok(ApiOkResponse.Response(o));
|
||||
}
|
||||
|
||||
|
||||
//======================================================================================================
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using EnumsNET;
|
||||
using PuppeteerSharp;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
@@ -160,6 +162,25 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//GET LIST
|
||||
//
|
||||
internal async Task<List<NameIdItem>> GetReportListAsync(AyaType ayType)
|
||||
{
|
||||
var rpts = await ct.Report.AsNoTracking().Where(z=>z.ObjectType==ayType && z.Active==true).Select(z=> new {id=z.Id,name=z.Name,roles=z.Roles}).ToListAsync();
|
||||
var ret=new List<NameIdItem>();
|
||||
foreach(var item in rpts){
|
||||
if(CurrentUserRoles.HasAnyFlags(item.roles)){
|
||||
ret.Add(new NameIdItem(){Name=item.name,Id=item.id});
|
||||
}
|
||||
}
|
||||
|
||||
//Sort by name
|
||||
return ret.OrderBy(z=>z.Name).ToList();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//SEARCH
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user