fix for poet by url
This commit is contained in:
parent
a902cf8853
commit
14ac8201fc
@ -58,6 +58,28 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// poet by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("poet")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetPoetByUrl(string url)
|
||||
{
|
||||
RServiceResult<GanjoorPoetCompleteViewModel> res =
|
||||
await _ganjoorService.GetPoetByUrl(url);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
return NotFound();
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cat by id
|
||||
/// </summary>
|
||||
|
||||
@ -630,6 +630,13 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoetByUrl(System.String)">
|
||||
<summary>
|
||||
poet by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetCatById(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
cat by id
|
||||
@ -4672,11 +4679,19 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoetByUrl(System.String)">
|
||||
<summary>
|
||||
get poet by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetCatById(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
get cat by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="poems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemById(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean)">
|
||||
@ -5442,6 +5457,13 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoetByUrl(System.String)">
|
||||
<summary>
|
||||
get poet by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatById(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
get cat by id
|
||||
|
||||
@ -27,10 +27,18 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetPoetById(int id);
|
||||
|
||||
/// <summary>
|
||||
/// get poet by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetPoetByUrl(string url);
|
||||
|
||||
/// <summary>
|
||||
/// get cat by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = true);
|
||||
|
||||
|
||||
@ -88,6 +88,31 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get poet by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetPoetByUrl(string url)
|
||||
{
|
||||
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 && c.ParentId == null).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