#57 pre/next poem
This commit is contained in:
parent
21d0ff822f
commit
ce33f4ba85
@ -61,6 +61,7 @@ namespace RMuseum.Controllers
|
||||
/// cat by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("cat/{id}")]
|
||||
@ -68,10 +69,10 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetCatById(int id)
|
||||
public async Task<IActionResult> GetCatById(int id, bool poems = true)
|
||||
{
|
||||
RServiceResult<GanjoorPoetCompleteViewModel> res =
|
||||
await _ganjoorService.GetCatById(id);
|
||||
await _ganjoorService.GetCatById(id, poems);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
@ -84,12 +85,14 @@ namespace RMuseum.Controllers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="catInfo"></param>
|
||||
/// <param name="catPoems"></param>
|
||||
/// <param name="rhymes">not implemented yet</param>
|
||||
/// <param name="recitations"></param>
|
||||
/// <param name="images"></param>
|
||||
/// <param name="songs">not implemented yet</param>
|
||||
/// <param name="comments">not implemented yet</param>
|
||||
/// <param name="verseDetails"></param>
|
||||
/// <param name="navigation">next/previous</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("poem/{id}")]
|
||||
@ -97,10 +100,10 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetPoemById(int id, bool catInfo = true, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true)
|
||||
public async Task<IActionResult> GetPoemById(int id, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true)
|
||||
{
|
||||
RServiceResult<GanjoorPoemCompleteViewModel> res =
|
||||
await _ganjoorService.GetPoemById(id, catInfo, rhymes, recitations, images, songs, comments, verseDetails);
|
||||
await _ganjoorService.GetPoemById(id, catInfo, catPoems, rhymes, recitations, images, songs, comments, verseDetails, navigation);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
|
||||
@ -48,6 +48,16 @@ namespace RMuseum.Models.Ganjoor.ViewModels
|
||||
/// </summary>
|
||||
public GanjoorPoetCompleteViewModel Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Next Poem
|
||||
/// </summary>
|
||||
public GanjoorPoemSummaryViewModel Next { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Previous Poem
|
||||
/// </summary>
|
||||
public GanjoorPoemSummaryViewModel Previous { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// verses
|
||||
/// </summary>
|
||||
|
||||
@ -629,25 +629,28 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetCatById(System.Int32)">
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetCatById(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
cat by id
|
||||
</summary>
|
||||
<param name="id"></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)">
|
||||
<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
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="catInfo"></param>
|
||||
<param name="catPoems"></param>
|
||||
<param name="rhymes">not implemented yet</param>
|
||||
<param name="recitations"></param>
|
||||
<param name="images"></param>
|
||||
<param name="songs">not implemented yet</param>
|
||||
<param name="comments">not implemented yet</param>
|
||||
<param name="verseDetails"></param>
|
||||
<param name="navigation">next/previous</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemRecitations(System.Int32)">
|
||||
@ -3517,6 +3520,16 @@
|
||||
category
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCompleteViewModel.Next">
|
||||
<summary>
|
||||
Next Poem
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCompleteViewModel.Previous">
|
||||
<summary>
|
||||
Previous Poem
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCompleteViewModel.Verses">
|
||||
<summary>
|
||||
verses
|
||||
@ -4647,25 +4660,27 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetCatById(System.Int32)">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetCatById(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
get cat by id
|
||||
</summary>
|
||||
<param name="id"></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)">
|
||||
<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
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="catInfo"></param>
|
||||
<param name="catPoems"></param>
|
||||
<param name="rhymes"></param>
|
||||
<param name="recitations"></param>
|
||||
<param name="images"></param>
|
||||
<param name="songs"></param>
|
||||
<param name="comments"></param>
|
||||
<param name="verseDetails"></param>
|
||||
<param name="navigation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemRecitations(System.Int32)">
|
||||
@ -5414,11 +5429,12 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatById(System.Int32)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.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.Implementation.GanjoorService.GetPoemRecitations(System.Int32)">
|
||||
@ -5436,18 +5452,20 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemById(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.Boolean)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.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
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="catInfo"></param>
|
||||
<param name="catPoems"></param>
|
||||
<param name="rhymes"></param>
|
||||
<param name="recitations"></param>
|
||||
<param name="images"></param>
|
||||
<param name="songs"></param>
|
||||
<param name="comments"></param>
|
||||
<param name="verseDetails"></param>
|
||||
<param name="navigation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.Faal">
|
||||
|
||||
@ -31,7 +31,7 @@ namespace RMuseum.Services
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id);
|
||||
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = true);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -39,14 +39,16 @@ namespace RMuseum.Services
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="catInfo"></param>
|
||||
/// <param name="catPoems"></param>
|
||||
/// <param name="rhymes"></param>
|
||||
/// <param name="recitations"></param>
|
||||
/// <param name="images"></param>
|
||||
/// <param name="songs"></param>
|
||||
/// <param name="comments"></param>
|
||||
/// <param name="verseDetails"></param>
|
||||
/// <param name="navigation"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemCompleteViewModel>> GetPoemById(int id, bool catInfo = true, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true);
|
||||
Task<RServiceResult<GanjoorPoemCompleteViewModel>> GetPoemById(int id, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true);
|
||||
|
||||
/// <summary>
|
||||
/// get poem recitations (PlainText/HtmlText are intentionally empty)
|
||||
|
||||
@ -91,8 +91,9 @@ namespace RMuseum.Services.Implementation
|
||||
/// get cat by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="poems"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id)
|
||||
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -131,7 +132,7 @@ namespace RMuseum.Services.Implementation
|
||||
UrlSlug = c.UrlSlug
|
||||
}
|
||||
).ToListAsync(),
|
||||
Poems = await _context.GanjoorPoems.Where(p => p.CatId == cat.Id).OrderBy(p => p.Id).Select
|
||||
Poems = poems ? await _context.GanjoorPoems.Where(p => p.CatId == cat.Id).OrderBy(p => p.Id).Select
|
||||
(
|
||||
p => new GanjoorPoemSummaryViewModel()
|
||||
{
|
||||
@ -141,6 +142,8 @@ namespace RMuseum.Services.Implementation
|
||||
Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text
|
||||
}
|
||||
).ToListAsync()
|
||||
:
|
||||
null
|
||||
};
|
||||
|
||||
return new RServiceResult<GanjoorPoetCompleteViewModel>
|
||||
@ -275,14 +278,16 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="catInfo"></param>
|
||||
/// <param name="catPoems"></param>
|
||||
/// <param name="rhymes"></param>
|
||||
/// <param name="recitations"></param>
|
||||
/// <param name="images"></param>
|
||||
/// <param name="songs"></param>
|
||||
/// <param name="comments"></param>
|
||||
/// <param name="verseDetails"></param>
|
||||
/// <param name="navigation"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoemCompleteViewModel>> GetPoemById(int id, bool catInfo = true, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true)
|
||||
public async Task<RServiceResult<GanjoorPoemCompleteViewModel>> GetPoemById(int id, bool catInfo = true, bool catPoems = false , bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -294,13 +299,60 @@ namespace RMuseum.Services.Implementation
|
||||
GanjoorPoetCompleteViewModel cat = null;
|
||||
if(catInfo)
|
||||
{
|
||||
var catRes = await GetCatById(poem.CatId);
|
||||
var catRes = await GetCatById(poem.CatId, catPoems);
|
||||
if(!string.IsNullOrEmpty(catRes.ExceptionString))
|
||||
{
|
||||
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, catRes.ExceptionString);
|
||||
}
|
||||
cat = catRes.Result;
|
||||
}
|
||||
|
||||
GanjoorPoemSummaryViewModel next = null;
|
||||
if(navigation)
|
||||
{
|
||||
int? nextId = await _context.GanjoorPoems
|
||||
.Where(p => p.CatId == poem.CatId && p.Id > poem.Id)
|
||||
.MinAsync(p => p.Id);
|
||||
if(nextId != null)
|
||||
{
|
||||
next = await _context.GanjoorPoems.Where(p => p.Id == nextId).Select
|
||||
(
|
||||
p =>
|
||||
new GanjoorPoemSummaryViewModel()
|
||||
{
|
||||
Id = p.Id,
|
||||
Title = p.Title,
|
||||
UrlSlug = p.UrlSlug,
|
||||
Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text
|
||||
}
|
||||
).SingleAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GanjoorPoemSummaryViewModel previous = null;
|
||||
if (navigation)
|
||||
{
|
||||
int? preId = await _context.GanjoorPoems
|
||||
.Where(p => p.CatId == poem.CatId && p.Id < poem.Id)
|
||||
.MaxAsync(p => p.Id);
|
||||
if (preId != null)
|
||||
{
|
||||
previous = await _context.GanjoorPoems.Where(p => p.Id == preId).Select
|
||||
(
|
||||
p =>
|
||||
new GanjoorPoemSummaryViewModel()
|
||||
{
|
||||
Id = p.Id,
|
||||
Title = p.Title,
|
||||
UrlSlug = p.UrlSlug,
|
||||
Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text
|
||||
}
|
||||
).SingleAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PublicRecitationViewModel[] rc = null;
|
||||
if(recitations)
|
||||
{
|
||||
@ -350,6 +402,8 @@ namespace RMuseum.Services.Implementation
|
||||
HtmlText = poem.HtmlText,
|
||||
PlainText = poem.PlainText,
|
||||
Category = cat,
|
||||
Next = next,
|
||||
Previous = previous,
|
||||
Recitations = rc,
|
||||
Images = imgs,
|
||||
Verses = verses
|
||||
@ -383,7 +437,7 @@ namespace RMuseum.Services.Implementation
|
||||
break;
|
||||
}
|
||||
|
||||
return await GetPoemById(poemId, false, false, true, false, false, false, false);
|
||||
return await GetPoemById(poemId, false, false, true, false, false, false, false, false);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user