#59 API for ganjoor pages
This commit is contained in:
parent
f760e7e51e
commit
a452985c29
@ -126,6 +126,29 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// page by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("page")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetPageByUrl(string url, bool catPoems = true)
|
||||
{
|
||||
RServiceResult<GanjoorPageCompleteViewModel> res =
|
||||
await _ganjoorService.GetPageByUrl(url, catPoems);
|
||||
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>
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
/// </summary>
|
||||
public class GanjoorPageCompleteViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// Ganjoor Page Type
|
||||
/// </summary>
|
||||
|
||||
@ -653,6 +653,14 @@
|
||||
<param name="poems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPageByUrl(System.String,System.Boolean)">
|
||||
<summary>
|
||||
page by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<param name="poems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemById(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean)">
|
||||
<summary>
|
||||
get poem by id
|
||||
@ -3699,6 +3707,11 @@
|
||||
Ganjoor Page View Model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPageCompleteViewModel.Id">
|
||||
<summary>
|
||||
id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPageCompleteViewModel.GanjoorPageType">
|
||||
<summary>
|
||||
Ganjoor Page Type
|
||||
@ -4998,6 +5011,14 @@
|
||||
<param name="poems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPageByUrl(System.String,System.Boolean)">
|
||||
<summary>
|
||||
get page by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<param name="catPoems"></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)">
|
||||
<summary>
|
||||
Get Poem By Id
|
||||
@ -5806,6 +5827,14 @@
|
||||
<param name="poems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPageByUrl(System.String,System.Boolean)">
|
||||
<summary>
|
||||
get page by url
|
||||
</summary>
|
||||
<param name="url"></param>
|
||||
<param name="catPoems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemRecitations(System.Int32)">
|
||||
<summary>
|
||||
get poem recitations (PlainText/HtmlText are intentionally empty)
|
||||
|
||||
@ -50,6 +50,13 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = true);
|
||||
|
||||
/// <summary>
|
||||
/// get page by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="catPoems"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPageCompleteViewModel>> GetPageByUrl(string url, bool catPoems = true);
|
||||
|
||||
/// <summary>
|
||||
/// Get Poem By Id
|
||||
|
||||
@ -271,6 +271,98 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get page by url
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="catPoems"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPageCompleteViewModel>> GetPageByUrl(string url, bool catPoems = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(url.IndexOf('?') != -1)
|
||||
{
|
||||
url = url.Substring(0, url.IndexOf('?'));
|
||||
}
|
||||
|
||||
// /hafez/ => /hafez :
|
||||
if (url.LastIndexOf('/') == url.Length - 1)
|
||||
{
|
||||
url = url.Substring(0, url.Length - 1);
|
||||
}
|
||||
|
||||
var dbPage = await _context.GanjoorPages.Where(p => p.FullUrl == url).SingleOrDefaultAsync();
|
||||
if (dbPage == null)
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null); //not found
|
||||
var secondPoet = dbPage.SecondPoetId == null ? null :
|
||||
await
|
||||
(from poet in _context.GanjoorPoets
|
||||
join cat in _context.GanjoorCategories.Where(c => c.ParentId == null)
|
||||
on poet.Id equals cat.PoetId
|
||||
where poet.Id == (int)dbPage.SecondPoetId
|
||||
orderby poet.Name descending
|
||||
select new GanjoorPoetViewModel()
|
||||
{
|
||||
Id = poet.Id,
|
||||
Name = poet.Name,
|
||||
FullUrl = cat.FullUrl,
|
||||
RootCatId = cat.Id
|
||||
}
|
||||
)
|
||||
.SingleAsync();
|
||||
GanjoorPageCompleteViewModel page = new GanjoorPageCompleteViewModel()
|
||||
{
|
||||
Id = dbPage.Id,
|
||||
GanjoorPageType = dbPage.GanjoorPageType,
|
||||
Title = dbPage.Title,
|
||||
FullTitle = dbPage.FullTitle,
|
||||
UrlSlug = dbPage.UrlSlug,
|
||||
FullUrl = dbPage.FullUrl,
|
||||
HtmlText = dbPage.HtmlText,
|
||||
SecondPoet = secondPoet
|
||||
|
||||
};
|
||||
switch (page.GanjoorPageType)
|
||||
{
|
||||
case GanjoorPageType.PoemPage:
|
||||
{
|
||||
var poemRes = await GetPoemById((int)dbPage.PoemId);
|
||||
if(!string.IsNullOrEmpty(poemRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null, poemRes.ExceptionString);
|
||||
}
|
||||
page.Poem = poemRes.Result;
|
||||
}
|
||||
break;
|
||||
case GanjoorPageType.PoetPage:
|
||||
{
|
||||
var poetRes = await GetPoetById((int)dbPage.PoetId);
|
||||
if(!string.IsNullOrEmpty(poetRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null, poetRes.ExceptionString);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GanjoorPageType.CatPage:
|
||||
{
|
||||
var catRes = await GetCatById((int)dbPage.CatId);
|
||||
if(!string.IsNullOrEmpty(catRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null, catRes.ExceptionString);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(page);
|
||||
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user