diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index 5c13c7ca..1842eb93 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -1883,89 +1883,30 @@ namespace RMuseum.Controllers
}
- ///
- /// bookmark verse
- ///
- ///
- ///
- ///
- [HttpPost]
- [Route("bookmark/{poemId}/{vOrder}")]
- [Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))]
- [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task BookmarkVerse(int poemId, int vOrder)
- {
- Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.BookmarkVerse(poemId, vOrder, loggedOnUserId, RBookmarkType.Bookmark);
- if (!string.IsNullOrEmpty(res.ExceptionString))
- return BadRequest(res.ExceptionString);
- return Ok(res.Result);
- }
-
- ///
- /// delete bookmark / fav / private note
- ///
- ///
- ///
- [HttpDelete]
- [Route("bookmark/{bookmarkId}")]
- [Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK)]
- [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task DeleteBookmark(Guid bookmarkId)
- {
- Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.DeleteGanjoorBookmark(bookmarkId, loggedOnUserId);
- if (!string.IsNullOrEmpty(res.ExceptionString))
- return BadRequest(res.ExceptionString);
- return Ok();
- }
///
/// switch bookmark
///
///
- ///
+ ///
///
[HttpPost]
- [Route("bookmark/switch/{poemId}/{vOrder}")]
+ [Route("bookmark/switch/{poemId}/{coupletIndex}")]
[Authorize]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task SwitchBookmark(int poemId, int vOrder)
+ public async Task SwitchCoupletBookmark(int poemId, int coupletIndex)
{
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.SwitchBookmarkVerse(poemId, vOrder, loggedOnUserId, RBookmarkType.Bookmark);
- if (!string.IsNullOrEmpty(res.ExceptionString))
- return BadRequest(res.ExceptionString);
- return Ok(res.Result);
- }
-
- ///
- /// fav poem
- ///
- ///
- ///
- ///
- [HttpPost]
- [Route("fav/{poemId}/{vOrder}")]
- [Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))]
- [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task FavArtifact(int poemId, int vOrder)
- {
- Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.BookmarkVerse(poemId, vOrder, loggedOnUserId, RBookmarkType.Favorite);
+ RServiceResult res = await _ganjoorService.SwitchCoupletBookmark(loggedOnUserId, poemId, coupletIndex);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
-
///
- /// poem bookmarks info
+ /// get poem user bookmarks
///
///
///
@@ -1974,49 +1915,30 @@ namespace RMuseum.Controllers
[Authorize]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task GetPoemGanjoorUserBookmarks(int poemId)
+ public async Task GetPoemUserBookmarks(int poemId)
{
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.GetPoemGanjoorUserBookmarks(poemId, loggedOnUserId, RBookmarkType.Bookmark);
+ RServiceResult res = await _ganjoorService.GetPoemUserBookmarks(loggedOnUserId, poemId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
///
- /// poem fav info
+ /// is the poem couplet is bookmarked by user
///
///
+ ///
///
[HttpGet]
- [Route("fav/{poemId}")]
+ [Route("bookmark/{poemId}/{coupletIndex}")]
[Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark[]))]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task GetPoemGanjoorUserFavs(int poemId)
+ public async Task IsCoupletBookmarked(int poemId, int coupletIndex)
{
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.GetPoemGanjoorUserBookmarks(poemId, loggedOnUserId, RBookmarkType.Favorite);
- if (!string.IsNullOrEmpty(res.ExceptionString))
- return BadRequest(res.ExceptionString);
- return Ok(res.Result);
- }
-
- ///
- /// item bookmarks info
- ///
- ///
- ///
- ///
- [HttpGet]
- [Route("bookmark/{poemId}/{vOrder}")]
- [Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark[]))]
- [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task GetVerseGanjoorUserBookmarks(int poemId, int vOrder)
- {
- Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult res = await _ganjoorService.GetVerseGanjoorUserBookmarks(poemId, vOrder, loggedOnUserId);
+ RServiceResult res = await _ganjoorService.IsCoupletBookmarked(loggedOnUserId, poemId, coupletIndex);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
@@ -2035,28 +1957,7 @@ namespace RMuseum.Controllers
{
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
- RServiceResult<(PaginationMetadata PagingMeta, GanjoorUserBookmark[] Bookmarks)> res = await _ganjoorService.GetUserBookmarks(paging, loggedOnUserId, RBookmarkType.Bookmark);
- if (!string.IsNullOrEmpty(res.ExceptionString))
- return BadRequest(res.ExceptionString);
- // Paging Header
- HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta));
- return Ok(res.Result.Bookmarks);
- }
-
- ///
- /// user favorites
- ///
- ///
- [HttpGet]
- [Route("fav")]
- [Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark[]))]
- [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task GetUserFavorites([FromQuery] PagingParameterModel paging)
- {
- Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
-
- RServiceResult<(PaginationMetadata PagingMeta, GanjoorUserBookmark[] Bookmarks)> res = await _ganjoorService.GetUserBookmarks(paging, loggedOnUserId, RBookmarkType.Favorite);
+ RServiceResult<(PaginationMetadata PagingMeta, GanjoorUserBookmark[] Bookmarks)> res = await _ganjoorService.GetUserBookmarks(paging, loggedOnUserId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
// Paging Header
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index c7226515..3ad7158c 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -1210,57 +1210,27 @@
-
-
- bookmark verse
-
-
-
-
-
-
-
- delete bookmark / fav / private note
-
-
-
-
-
+
switch bookmark
-
+
-
+
- fav poem
-
-
-
-
-
-
-
- poem bookmarks info
+ get poem user bookmarks
-
+
- poem fav info
+ is the poem couplet is bookmarked by user
-
-
-
-
- item bookmarks info
-
-
-
+
@@ -1269,12 +1239,6 @@
-
-
- user favorites
-
-
-
readonly mode
@@ -8657,59 +8621,38 @@
-
+
- Bookmark Verse
+ Switch Bookmark for couplet
-
-
-
+
+
-
-
- Switch Bookmark Verse
-
-
-
-
-
-
-
-
+
get user ganjoor bookmarks
-
-
+
-
+
get verse bookmarks
-
-
+
+
-
-
- delete user bookmark
- ///
-
- to make sure a user can not delete another user's bookmarks
-
-
-
+
get user bookmarks (artifacts and items)
-
@@ -9754,42 +9697,39 @@
IGanjoorService implementation
-
+
+
+ Switch Bookmark for couplet
+
+
+
+
+
+
+
Bookmark Verse
-
+
-
-
-
- Bookmark Verse
-
-
-
-
-
-
-
-
+
get user ganjoor bookmarks
-
-
+
-
+
get verse bookmarks
-
-
+
+
@@ -9800,13 +9740,12 @@
to make sure a user can not delete another user's bookmarks
-
+
get user bookmarks (artifacts and items)
-
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index 40b29b9e..8a8e3625 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -567,59 +567,40 @@ namespace RMuseum.Services
///
RServiceResult StartUpdatingMundexPage(Guid editingUserId);
- ///
- /// Bookmark Verse
- ///
- ///
- ///
- ///
- ///
- ///
- Task> BookmarkVerse(int poemId, int vOrder, Guid userId, RBookmarkType type);
///
- /// Switch Bookmark Verse
+ /// Switch Bookmark for couplet
///
- ///
- ///
///
- ///
+ ///
+ ///
///
- Task> SwitchBookmarkVerse(int poemId, int vOrder, Guid userId, RBookmarkType type);
+ Task> SwitchCoupletBookmark(Guid userId, int poemId, int coupletIndex);
///
/// get user ganjoor bookmarks
///
- ///
///
- ///
+ ///
///
- Task> GetPoemGanjoorUserBookmarks(int poemId, Guid userId, RBookmarkType type);
+ Task> GetPoemUserBookmarks(Guid userId, int poemId);
///
/// get verse bookmarks
///
- ///
- ///
///
+ ///
+ ///
///
- Task> GetVerseGanjoorUserBookmarks(int poemId, int vOrder, Guid userId);
+ Task> IsCoupletBookmarked(Guid userId, int poemId, int coupletIndex);
- ///
- /// delete user bookmark
- /// ///
- ///
- /// to make sure a user can not delete another user's bookmarks
- ///
- Task> DeleteGanjoorBookmark(Guid bookmarkId, Guid userId);
///
/// get user bookmarks (artifacts and items)
///
///
///
- ///
///
- Task> GetUserBookmarks(PagingParameterModel paging, Guid userId, RBookmarkType type);
+ Task> GetUserBookmarks(PagingParameterModel paging, Guid userId);
}
}
diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs
index 4a9794c4..a858e2a9 100644
--- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs
+++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs
@@ -17,17 +17,18 @@ namespace RMuseum.Services.Implementation
public partial class GanjoorService : IGanjoorService
{
///
- /// Bookmark Verse
+ /// Switch Bookmark for couplet
///
- ///
- ///
///
- ///
+ ///
+ ///
///
- public async Task> SwitchBookmarkVerse(int poemId, int vOrder, Guid userId, RBookmarkType type)
+ public async Task> SwitchCoupletBookmark(Guid userId, int poemId, int coupletIndex)
{
- var verse = await _context.GanjoorVerses.Where(v => v.PoemId == poemId && v.VOrder == vOrder).SingleAsync();
- var bookmark = await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verse.Id && b.RBookmarkType == type).SingleOrDefaultAsync();
+ int? verseId = await _GetVerseIdFromCoupletIndex(poemId, coupletIndex);
+ if (verseId == null)
+ return new RServiceResult(null, "verse not found");
+ var bookmark = await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verseId).SingleOrDefaultAsync();
if (bookmark != null)
{
var res = await DeleteGanjoorBookmark(bookmark.Id, userId);
@@ -38,7 +39,7 @@ namespace RMuseum.Services.Implementation
}
else
{
- var res = await BookmarkVerse(poemId, vOrder, userId, type);
+ var res = await BookmarkVerse(poemId, (int)verseId, userId);
if(!string.IsNullOrEmpty(res.ExceptionString))
return res;
bookmark = res.Result;
@@ -51,16 +52,14 @@ namespace RMuseum.Services.Implementation
/// Bookmark Verse
///
///
- ///
+ ///
///
- ///
///
- public async Task> BookmarkVerse(int poemId, int vOrder, Guid userId, RBookmarkType type)
+ public async Task> BookmarkVerse(int poemId, int verseId, Guid userId)
{
- var verse = await _context.GanjoorVerses.Where(v => v.PoemId == poemId && v.VOrder == vOrder).SingleAsync();
- if ((await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verse.Id && b.RBookmarkType == type).SingleOrDefaultAsync()) != null)
+ if ((await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verseId).SingleOrDefaultAsync()) != null)
{
- return new RServiceResult(null, "Artifact is already bookmarked/faved.");
+ return new RServiceResult(null, "Verse is already bookmarkeded.");
}
GanjoorUserBookmark bookmark =
@@ -68,8 +67,7 @@ namespace RMuseum.Services.Implementation
{
UserId = userId,
PoemId = poemId,
- VerseId = verse.Id,
- RBookmarkType = type,
+ VerseId = verseId,
DateTime = DateTime.Now,
Note = ""
};
@@ -83,28 +81,28 @@ namespace RMuseum.Services.Implementation
///
/// get user ganjoor bookmarks
///
- ///
///
- ///
+ ///
///
- public async Task> GetPoemGanjoorUserBookmarks(int poemId, Guid userId, RBookmarkType type)
+ public async Task> GetPoemUserBookmarks(Guid userId, int poemId)
{
- GanjoorUserBookmark[] bookmarks = await _context.GanjoorUserBookmarks.Where(b => b.PoemId == poemId && b.UserId == userId && b.RBookmarkType == type).ToArrayAsync();
+ GanjoorUserBookmark[] bookmarks = await _context.GanjoorUserBookmarks.Where(b => b.PoemId == poemId && b.UserId == userId).ToArrayAsync();
return new RServiceResult(bookmarks);
}
///
/// get verse bookmarks
///
- ///
- ///
///
+ ///
+ ///
///
- public async Task> GetVerseGanjoorUserBookmarks(int poemId, int vOrder, Guid userId)
+ public async Task> IsCoupletBookmarked(Guid userId, int poemId, int coupletIndex)
{
- var verse = await _context.GanjoorVerses.Where(v => v.PoemId == poemId && v.VOrder == vOrder).SingleAsync();
- GanjoorUserBookmark[] bookmarks = await _context.GanjoorUserBookmarks.Where(b => b.PoemId == poemId && b.VerseId == verse.Id && b.UserId == userId).ToArrayAsync();
- return new RServiceResult(bookmarks);
+ int? verseId = await _GetVerseIdFromCoupletIndex(poemId, coupletIndex);
+ if (verseId == null)
+ return new RServiceResult(false, "verse not found");
+ return new RServiceResult(await _context.GanjoorUserBookmarks.Where(b => b.PoemId == poemId && b.VerseId == verseId && b.UserId == userId).AnyAsync());
}
@@ -131,15 +129,14 @@ namespace RMuseum.Services.Implementation
///
///
///
- ///
///
- public async Task> GetUserBookmarks(PagingParameterModel paging, Guid userId, RBookmarkType type)
+ public async Task> GetUserBookmarks(PagingParameterModel paging, Guid userId)
{
var source =
_context.GanjoorUserBookmarks
.Include(b => b.Poem)
.Include(b => b.Verse)
- .Where(b => b.UserId == userId && b.RBookmarkType == type)
+ .Where(b => b.UserId == userId)
.OrderByDescending(b => b.DateTime)
.AsQueryable();