docs: #314 changing bookmarking API to allow bookmarking comments

This commit is contained in:
Hamid Reza Mohammadi 2022-05-03 19:57:18 +04:30
parent aa7a8451ea
commit 2c9993cf24
3 changed files with 62 additions and 7 deletions

View File

@ -2392,7 +2392,7 @@ namespace RMuseum.Controllers
/// switch bookmark
/// </summary>
/// <param name="poemId"></param>
/// <param name="coupletIndex"></param>
/// <param name="coupletIndex">if you send a negative number it means you are trying to bookmark a comment</param>
/// <returns></returns>
[HttpPost]
[Route("bookmark/switch/{poemId}/{coupletIndex}")]

View File

@ -1567,7 +1567,7 @@
switch bookmark
</summary>
<param name="poemId"></param>
<param name="coupletIndex"></param>
<param name="coupletIndex">if you send a negative number it means you are trying to bookmark a comment</param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.BookmarkCoupletIfNotBookmarked(System.Int32,System.Int32)">
@ -13413,6 +13413,15 @@
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.BookmarkComment(System.Int32,System.Int32,System.Guid)">
<summary>
bookmark comment
</summary>
<param name="poemId"></param>
<param name="negativeCommentId"></param>
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemUserBookmarks(System.Guid,System.Int32)">
<summary>
get user ganjoor bookmarks (only Id, CoupletIndex and DateTime are valid)

View File

@ -32,14 +32,23 @@ namespace RMuseum.Services.Implementation
if (!string.IsNullOrEmpty(res.ExceptionString))
return new RServiceResult<GanjoorUserBookmark>(null, res.ExceptionString);
bookmark = null;
}
else
{
var res = await BookmarkVerse(poemId, coupletIndex, userId);
if(!string.IsNullOrEmpty(res.ExceptionString))
return res;
bookmark = res.Result;
if(coupletIndex < 0)//bookmark a comment
{
var res = await BookmarkComment(poemId, coupletIndex, userId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return res;
bookmark = res.Result;
}
else
{
var res = await BookmarkVerse(poemId, coupletIndex, userId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return res;
bookmark = res.Result;
}
}
return new RServiceResult<GanjoorUserBookmark>(bookmark);
}
@ -94,6 +103,43 @@ namespace RMuseum.Services.Implementation
return new RServiceResult<GanjoorUserBookmark>(bookmark);
}
/// <summary>
/// bookmark comment
/// </summary>
/// <param name="poemId"></param>
/// <param name="negativeCommentId"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorUserBookmark>> BookmarkComment(int poemId, int negativeCommentId, Guid userId)
{
if ((await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.CoupletIndex == negativeCommentId).SingleOrDefaultAsync()) != null)
{
return new RServiceResult<GanjoorUserBookmark>(null, "The comment is already bookmarkeded.");
}
int commentId = -negativeCommentId;
var comment = await _context.GanjoorComments.AsNoTracking().Where(c => c.Id == commentId).SingleOrDefaultAsync();
if(comment == null)
{
return new RServiceResult<GanjoorUserBookmark>(null, "The comment is deleted.");
}
GanjoorUserBookmark bookmark =
new GanjoorUserBookmark()
{
UserId = userId,
PoemId = poemId,
DateTime = DateTime.Now,
CoupletIndex = negativeCommentId,
PrivateNote = comment.HtmlComment,
};
_context.GanjoorUserBookmarks.Add(bookmark);
await _context.SaveChangesAsync();
return new RServiceResult<GanjoorUserBookmark>(bookmark);
}
/// <summary>
/// get user ganjoor bookmarks (only Id, CoupletIndex and DateTime are valid)
/// </summary>