#211 additional api for bookmarking
This commit is contained in:
parent
68441d3481
commit
b7b2e5affe
@ -1895,6 +1895,7 @@ namespace RMuseum.Controllers
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> SwitchCoupletBookmark(int poemId, int coupletIndex)
|
||||
{
|
||||
if (ReadOnlyMode)
|
||||
@ -1902,7 +1903,38 @@ namespace RMuseum.Controllers
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<GanjoorUserBookmark> res = await _ganjoorService.SwitchCoupletBookmark(loggedOnUserId, poemId, coupletIndex);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
if (res.ExceptionString == "verse not found")
|
||||
return NotFound();
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
return Ok(res.Result != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bookmark couplet if it is not
|
||||
/// </summary>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("bookmark/{poemId}/{coupletIndex}")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> BookmarkCoupletIfNotBookmarked(int poemId, int coupletIndex)
|
||||
{
|
||||
if (ReadOnlyMode)
|
||||
return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید.");
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<GanjoorUserBookmark> res = await _ganjoorService.BookmarkCoupletIfNotBookmarked(loggedOnUserId, poemId, coupletIndex);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
if (res.ExceptionString == "verse not found")
|
||||
return NotFound();
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
return Ok(res.Result != null);
|
||||
}
|
||||
|
||||
@ -1958,12 +1990,17 @@ namespace RMuseum.Controllers
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> IsCoupletBookmarked(int poemId, int coupletIndex)
|
||||
{
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<bool> res = await _ganjoorService.IsCoupletBookmarked(loggedOnUserId, poemId, coupletIndex);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
if (res.ExceptionString == "verse not found")
|
||||
return NotFound();
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
|
||||
@ -1218,6 +1218,14 @@
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.BookmarkCoupletIfNotBookmarked(System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Bookmark couplet if it is not
|
||||
</summary>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.DeleteBookmark(System.Guid)">
|
||||
<summary>
|
||||
delete bookmark
|
||||
@ -8695,6 +8703,15 @@
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.BookmarkCoupletIfNotBookmarked(System.Guid,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Bookmark couplet if it is not
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteGanjoorBookmark(System.Guid,System.Guid)">
|
||||
<summary>
|
||||
delete user bookmark
|
||||
@ -9779,6 +9796,15 @@
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.BookmarkCoupletIfNotBookmarked(System.Guid,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Bookmark couplet if it is not
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.BookmarkVerse(System.Int32,System.Int32,System.Int32,System.Nullable{System.Int32},System.Guid)">
|
||||
<summary>
|
||||
Bookmark Verse
|
||||
|
||||
@ -576,6 +576,15 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorUserBookmark>> SwitchCoupletBookmark(Guid userId, int poemId, int coupletIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Bookmark couplet if it is not
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorUserBookmark>> BookmarkCoupletIfNotBookmarked(Guid userId, int poemId, int coupletIndex);
|
||||
|
||||
/// <summary>
|
||||
/// delete user bookmark
|
||||
/// /// </summary>
|
||||
|
||||
@ -47,6 +47,29 @@ namespace RMuseum.Services.Implementation
|
||||
return new RServiceResult<GanjoorUserBookmark>(bookmark);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bookmark couplet if it is not
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorUserBookmark>> BookmarkCoupletIfNotBookmarked(Guid userId, int poemId, int coupletIndex)
|
||||
{
|
||||
(int Verse1, int? Verse2)? verse12 = await _GetVerse12IdFromCoupletIndex(poemId, coupletIndex);
|
||||
if (verse12 == null)
|
||||
return new RServiceResult<GanjoorUserBookmark>(null, "verse not found");
|
||||
var bookmark = await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verse12.Value.Verse1).SingleOrDefaultAsync();
|
||||
if (bookmark == null)
|
||||
{
|
||||
var res = await BookmarkVerse(poemId, coupletIndex, verse12.Value.Verse1, verse12.Value.Verse2, userId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return res;
|
||||
bookmark = res.Result;
|
||||
}
|
||||
return new RServiceResult<GanjoorUserBookmark>(bookmark);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Bookmark Verse
|
||||
|
||||
Loading…
Reference in New Issue
Block a user