This commit is contained in:
2018-12-19 19:28:55 +00:00
parent 6c5b726210
commit 22ac04a35f
2 changed files with 43 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ namespace AyaNova.Api.Controllers
[Route("api/v{version:apiVersion}/[controller]")]
[Produces("application/json")]
[Authorize]
public class TagPickListController : Controller
public class TagListController : Controller
{
private readonly AyContext ct;
private readonly ILogger<AyaTypeController> log;
@@ -32,7 +32,7 @@ namespace AyaNova.Api.Controllers
/// <param name="dbcontext"></param>
/// <param name="logger"></param>
/// <param name="apiServerState"></param>
public TagPickListController(AyContext dbcontext, ILogger<AyaTypeController> logger, ApiServerState apiServerState)
public TagListController(AyContext dbcontext, ILogger<AyaTypeController> logger, ApiServerState apiServerState)
{
ct = dbcontext;
log = logger;
@@ -60,6 +60,25 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Get tag cloud list
///
/// Required roles: Any
/// </summary>
/// <param name="query">The query to filter the returned list by</param>
/// <returns>List</returns>
[HttpGet("cloudlist")]
public ActionResult GetCloudList([FromQuery]string query)
{
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
return Ok(new ApiOkResponse(TagUtil.CloudListFiltered(ct, query)));
}
// /// <summary>
// /// Get all possible enumerated values picklist key names

View File

@@ -166,6 +166,28 @@ namespace AyaNova.Biz
}
}
//Cloud list
public static List<TagCloudItem> CloudListFiltered(AyContext ct, string q)
{
//This path is intended for internal use and accepts that there may not be a filter specified
//however the client will always require a filter to display a tag list for choosing from
if (string.IsNullOrWhiteSpace(q))
{
return ct.Tag.OrderByDescending(x => x.RefCount).Select(x => new TagCloudItem() { Name = x.Name, ReferenceCount = x.RefCount }).ToList();
}
else
{
q = NormalizeTag(q);
return ct.Tag.Where(x => x.Name.Contains(q)).OrderByDescending(x => x.RefCount).Select(x => new TagCloudItem() { Name = x.Name, ReferenceCount = x.RefCount }).ToList();
}
}
}//eoc
public class TagCloudItem
{
public long ReferenceCount { get; set; }
public string Name { get; set; }
}
}//ens