get category by url
This commit is contained in:
parent
14ac8201fc
commit
e6f6be5d0e
@ -103,6 +103,29 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cat by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("cat")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetCatByUrl(string url, bool poems = true)
|
||||
{
|
||||
RServiceResult<GanjoorPoetCompleteViewModel> res =
|
||||
await _ganjoorService.GetCatByUrl(url, poems);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
return NotFound();
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get poem by id
|
||||
/// </summary>
|
||||
|
||||
@ -42,6 +42,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = true);
|
||||
|
||||
/// <summary>
|
||||
/// get cat by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = true);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Poem By Id
|
||||
|
||||
@ -113,6 +113,32 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get cat by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
// /hafez/ => /hafez :
|
||||
if (url.LastIndexOf('/') == url.Length - 1)
|
||||
{
|
||||
url = url.Substring(0, url.Length - 1);
|
||||
}
|
||||
var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).SingleOrDefaultAsync();
|
||||
if (cat == null)
|
||||
return new RServiceResult<GanjoorPoetCompleteViewModel>(null);
|
||||
return await GetCatById(cat.Id);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorPoetCompleteViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get cat by id
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user