#128 simpified poets listing api

This commit is contained in:
Hamid Reza Mohammadi 2021-06-04 09:55:07 +04:30
parent 5a64da84ba
commit 01c73fe8fc
6 changed files with 20 additions and 24 deletions

View File

@ -461,10 +461,10 @@ namespace GanjooRazor.Pages
private async Task preparePoets()
{
var cacheKey = $"/api/ganjoor/poets?includeBio=false";
var cacheKey = $"/api/ganjoor/poets";
if (!_memoryCache.TryGetValue(cacheKey, out List<GanjoorPoetViewModel> poets))
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets?includeBio=false");
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets");
response.EnsureSuccessStatusCode();
poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoetViewModel>>();
_memoryCache.Set(cacheKey, poets);

View File

@ -65,10 +65,10 @@ namespace GanjooRazor.Pages
private async Task preparePoets()
{
var cacheKey = $"/api/ganjoor/poets?includeBio=false";
var cacheKey = $"/api/ganjoor/poets";
if (!_memoryCache.TryGetValue(cacheKey, out List<GanjoorPoetViewModel> poets))
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets?includeBio=false");
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets");
response.EnsureSuccessStatusCode();
poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoetViewModel>>();
_memoryCache.Set(cacheKey, poets);

View File

@ -28,23 +28,21 @@ namespace RMuseum.Controllers
public class GanjoorController : Controller
{
/// <summary>
/// get list of poets
/// get list of published poets without their biography
/// </summary>
/// <param name="websitePoets"></param>
/// <param name="includeBio"></param>
/// <returns></returns>
[HttpGet]
[Route("poets")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetViewModel[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPoets(bool websitePoets = true, bool includeBio = true)
public async Task<IActionResult> GetPoets()
{
var cacheKey = $"ganjoor/poets/{websitePoets}/{includeBio}";
var cacheKey = $"ganjoor/poets";
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetViewModel[] poets))
{
RServiceResult<GanjoorPoetViewModel[]> res =
await _ganjoorService.GetPoets(websitePoets, includeBio);
await _ganjoorService.GetPoets(true, false);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);

View File

@ -584,12 +584,10 @@
<param name="auditLogService">
</param>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetPoets(System.Boolean,System.Boolean)">
<member name="M:RMuseum.Controllers.GanjoorController.GetPoets">
<summary>
get list of poets
get list of published poets without their biography
</summary>
<param name="websitePoets"></param>
<param name="includeBio"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetPoetById(System.Int32)">
@ -6609,7 +6607,7 @@
<summary>
Get List of poets
</summary>
<param name="websitePoets"></param>
<param name="published"></param>
<param name="includeBio"></param>
<returns></returns>
</member>
@ -7747,7 +7745,7 @@
<summary>
Get List of poets
</summary>
<param name="websitePoets"></param>
<param name="published"></param>
<param name="includeBio"></param>
<returns></returns>
</member>

View File

@ -15,10 +15,10 @@ namespace RMuseum.Services
/// <summary>
/// Get List of poets
/// </summary>
/// <param name="websitePoets"></param>
/// <param name="published"></param>
/// <param name="includeBio"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool websitePoets, bool includeBio = true);
Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool published, bool includeBio = true);
/// <summary>
/// get poet by id

View File

@ -30,15 +30,15 @@ namespace RMuseum.Services.Implementation
/// <summary>
/// Get List of poets
/// </summary>
/// <param name="websitePoets"></param>
/// <param name="published"></param>
/// <param name="includeBio"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool websitePoets, bool includeBio = true)
public async Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool published, bool includeBio = true)
{
try
{
var cacheKey = $"/api/ganjoor/poets?websitePoets={websitePoets}&includeBio={includeBio}";
var cacheKey = $"/api/ganjoor/poets?published={published}&includeBio={includeBio}";
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetViewModel[] poets))
{
var res =
@ -46,7 +46,7 @@ namespace RMuseum.Services.Implementation
(from poet in _context.GanjoorPoets
join cat in _context.GanjoorCategories.Where(c => c.ParentId == null)
on poet.Id equals cat.PoetId
where poet.Published
where !published || poet.Published
select new GanjoorPoetViewModel()
{
Id = poet.Id,
@ -2295,12 +2295,12 @@ namespace RMuseum.Services.Implementation
await _context.SaveChangesAsync();
var cachKeyPoets = $"/api/ganjoor/poets?websitePoets=true&includeBio=false";
var cachKeyPoets = $"/api/ganjoor/poets?published=true&includeBio=false";
if (_memoryCache.TryGetValue(cachKeyPoets, out GanjoorPoetViewModel[] poets))
{
_memoryCache.Remove(cachKeyPoets);
}
var cachKeyPoets2 = $"ganjoor/poets/true/false";
var cachKeyPoets2 = $"ganjoor/poets";
if (_memoryCache.TryGetValue(cachKeyPoets2, out GanjoorPoetViewModel[] poets2))
{
_memoryCache.Remove(cachKeyPoets2);