#495 rating comments
This commit is contained in:
parent
9d32aa27c0
commit
1b613ba397
@ -1199,6 +1199,7 @@ namespace RMuseum.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="coupletIndex"></param>
|
/// <param name="coupletIndex"></param>
|
||||||
|
/// <param name="sortByRanking">true: order by rating then date, false: order by date</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -1206,10 +1207,31 @@ namespace RMuseum.Controllers
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCommentSummaryViewModel[]))]
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCommentSummaryViewModel[]))]
|
||||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||||
public async Task<IActionResult> GetPoemComments(int id, int? coupletIndex)
|
public async Task<IActionResult> GetPoemComments(int id, int? coupletIndex, bool sortByRanking = true)
|
||||||
{
|
{
|
||||||
RServiceResult<GanjoorCommentSummaryViewModel[]> res =
|
RServiceResult<GanjoorCommentSummaryViewModel[]> res =
|
||||||
await _ganjoorService.GetPoemComments(id, Guid.Empty, coupletIndex);
|
await _ganjoorService.GetPoemComments(id, Guid.Empty, coupletIndex, sortByRanking);
|
||||||
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||||
|
return BadRequest(res.ExceptionString);
|
||||||
|
return Ok(res.Result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rate a comment (like / dislike / clear rating)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">comment id</param>
|
||||||
|
/// <param name="value">+1: like, -1: dislike, 0: remove previous rating</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("poem/comment/{id}/rate")]
|
||||||
|
[Authorize]
|
||||||
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||||
|
public async Task<IActionResult> RateComment(int id, short value)
|
||||||
|
{
|
||||||
|
Guid userId = new Guid(User.Claims.First(c => c.Type == "UserId").Value);
|
||||||
|
RServiceResult<bool> res =
|
||||||
|
await _ganjoorService.RateCommentAsync(userId, id, value);
|
||||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||||
return BadRequest(res.ExceptionString);
|
return BadRequest(res.ExceptionString);
|
||||||
return Ok(res.Result);
|
return Ok(res.Result);
|
||||||
|
|||||||
@ -254,6 +254,15 @@ namespace RMuseum.DbContext
|
|||||||
.HasIndex(i => new { i.GanjoorCommentId, i.UserId })
|
.HasIndex(i => new { i.GanjoorCommentId, i.UserId })
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
builder.Entity<GanjoorCommentReaction>()
|
||||||
|
.HasIndex(i => new { i.PoemId, i.UserId });
|
||||||
|
|
||||||
|
builder.Entity<GanjoorComment>()
|
||||||
|
.HasIndex(i => new { i.PoemId, i.SortKey });
|
||||||
|
|
||||||
|
builder.Entity<GanjoorComment>()
|
||||||
|
.HasIndex(i => new { i.PoemId, i.CommentDate });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1358,7 +1358,7 @@
|
|||||||
<param name="url"></param>
|
<param name="url"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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,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,System.Boolean,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
get poem by id
|
get poem by id
|
||||||
</summary>
|
</summary>
|
||||||
@ -1373,6 +1373,7 @@
|
|||||||
<param name="verseDetails"></param>
|
<param name="verseDetails"></param>
|
||||||
<param name="navigation">next/previous</param>
|
<param name="navigation">next/previous</param>
|
||||||
<param name="relatedpoems"></param>
|
<param name="relatedpoems"></param>
|
||||||
|
<param name="sortByRanking"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemVerses(System.Int32,System.Int32)">
|
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemVerses(System.Int32,System.Int32)">
|
||||||
@ -1429,12 +1430,21 @@
|
|||||||
<param name="trackType"></param>
|
<param name="trackType"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemComments(System.Int32,System.Nullable{System.Int32})">
|
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemComments(System.Int32,System.Nullable{System.Int32},System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
Get Poem Comments
|
Get Poem Comments
|
||||||
</summary>
|
</summary>
|
||||||
<param name="id"></param>
|
<param name="id"></param>
|
||||||
<param name="coupletIndex"></param>
|
<param name="coupletIndex"></param>
|
||||||
|
<param name="sortByRanking">true: order by rating then date, false: order by date</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:RMuseum.Controllers.GanjoorController.RateComment(System.Int32,System.Int16)">
|
||||||
|
<summary>
|
||||||
|
Rate a comment (like / dislike / clear rating)
|
||||||
|
</summary>
|
||||||
|
<param name="id">comment id</param>
|
||||||
|
<param name="value">+1: like, -1: dislike, 0: remove previous rating</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Controllers.GanjoorController.GetRelatedSections(System.Int32,System.Int32,System.Int32,System.Int32)">
|
<member name="M:RMuseum.Controllers.GanjoorController.GetRelatedSections(System.Int32,System.Int32,System.Int32,System.Int32)">
|
||||||
@ -16764,7 +16774,7 @@
|
|||||||
<param name="id"></param>
|
<param name="id"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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,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,System.Boolean,System.Boolean,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
Get Poem By Id
|
Get Poem By Id
|
||||||
</summary>
|
</summary>
|
||||||
@ -16780,6 +16790,7 @@
|
|||||||
<param name="navigation"></param>
|
<param name="navigation"></param>
|
||||||
<param name="relatedpoems"></param>
|
<param name="relatedpoems"></param>
|
||||||
<param name="sections"></param>
|
<param name="sections"></param>
|
||||||
|
<param name="sortByRanking"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemVersesAsync(System.Int32,System.Int32)">
|
<member name="M:RMuseum.Services.IGanjoorService.GetPoemVersesAsync(System.Int32,System.Int32)">
|
||||||
@ -16845,13 +16856,14 @@
|
|||||||
<param name="trackType"></param>
|
<param name="trackType"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemComments(System.Int32,System.Guid,System.Nullable{System.Int32})">
|
<member name="M:RMuseum.Services.IGanjoorService.GetPoemComments(System.Int32,System.Guid,System.Nullable{System.Int32},System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
get poem comments
|
get poem comments
|
||||||
</summary>
|
</summary>
|
||||||
<param name="poemId"></param>
|
<param name="poemId"></param>
|
||||||
<param name="userId"></param>
|
<param name="userId"></param>
|
||||||
<param name="coupletIndex"></param>
|
<param name="coupletIndex"></param>
|
||||||
|
<param name="sortByRanking">true: order by rating SortKey then CommentDate, false: order by CommentDate</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.IGanjoorService.GetCommentByIdAsync(System.Int32)">
|
<member name="M:RMuseum.Services.IGanjoorService.GetCommentByIdAsync(System.Int32)">
|
||||||
@ -16861,6 +16873,15 @@
|
|||||||
<param name="commentId"></param>
|
<param name="commentId"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.IGanjoorService.RateCommentAsync(System.Guid,System.Int32,System.Int16)">
|
||||||
|
<summary>
|
||||||
|
like / dislike / clear rating for a comment
|
||||||
|
</summary>
|
||||||
|
<param name="userId"></param>
|
||||||
|
<param name="commentId"></param>
|
||||||
|
<param name="value">+1: like, -1: dislike, 0: remove previous rating</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:RMuseum.Services.IGanjoorService.GetRelatedSections(System.Int32,System.Int32,System.Int32,System.Int32)">
|
<member name="M:RMuseum.Services.IGanjoorService.GetRelatedSections(System.Int32,System.Int32,System.Int32,System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
get a section related sections
|
get a section related sections
|
||||||
@ -20119,6 +20140,9 @@
|
|||||||
<summary>
|
<summary>
|
||||||
IGanjoorService implementation
|
IGanjoorService implementation
|
||||||
</summary>
|
</summary>
|
||||||
|
<summary>
|
||||||
|
IGanjoorService implementation
|
||||||
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.SwitchCoupletBookmark(System.Guid,System.Int32,System.Int32)">
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.SwitchCoupletBookmark(System.Guid,System.Int32,System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
@ -20321,6 +20345,15 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.RateCommentAsync(System.Guid,System.Int32,System.Int16)">
|
||||||
|
<summary>
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
<param name="userId"></param>
|
||||||
|
<param name="commentId"></param>
|
||||||
|
<param name="value">+1: like, -1: dislike, 0: remove previous rating</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetDigitalSourceFromTagAsync(System.String)">
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetDigitalSourceFromTagAsync(System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
get digital source from tag
|
get digital source from tag
|
||||||
@ -21342,13 +21375,14 @@
|
|||||||
<param name="userId"></param>
|
<param name="userId"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemComments(System.Int32,System.Guid,System.Nullable{System.Int32})">
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemComments(System.Int32,System.Guid,System.Nullable{System.Int32},System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
get poem comments
|
get poem comments
|
||||||
</summary>
|
</summary>
|
||||||
<param name="poemId"></param>
|
<param name="poemId"></param>
|
||||||
<param name="userId"></param>
|
<param name="userId"></param>
|
||||||
<param name="coupletIndex"></param>
|
<param name="coupletIndex"></param>
|
||||||
|
<param name="sortByRanking"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCommentByIdAsync(System.Int32)">
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCommentByIdAsync(System.Int32)">
|
||||||
@ -21482,7 +21516,7 @@
|
|||||||
<param name="coupletIndex"></param>
|
<param name="coupletIndex"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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,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,System.Boolean,System.Boolean,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
Get Poem By Id
|
Get Poem By Id
|
||||||
</summary>
|
</summary>
|
||||||
@ -21498,6 +21532,7 @@
|
|||||||
<param name="navigation"></param>
|
<param name="navigation"></param>
|
||||||
<param name="relatedpoems"></param>
|
<param name="relatedpoems"></param>
|
||||||
<param name="sections">sections</param>
|
<param name="sections">sections</param>
|
||||||
|
<param name="sortByRanking"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeletePoemCorrections(System.Guid,System.Int32)">
|
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeletePoemCorrections(System.Guid,System.Int32)">
|
||||||
@ -23552,6 +23587,11 @@
|
|||||||
<param name="userId"></param>
|
<param name="userId"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:RMuseum.Utils.GanjoorCommentRankingScoreCalculator">
|
||||||
|
<summary>
|
||||||
|
comment ranking score calculator
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Utils.GanjoorPoemTools">
|
<member name="T:RMuseum.Utils.GanjoorPoemTools">
|
||||||
<summary>
|
<summary>
|
||||||
ganjoor poem tools
|
ganjoor poem tools
|
||||||
|
|||||||
@ -212,8 +212,9 @@ namespace RMuseum.Services
|
|||||||
/// <param name="poemId"></param>
|
/// <param name="poemId"></param>
|
||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="coupletIndex"></param>
|
/// <param name="coupletIndex"></param>
|
||||||
|
/// <param name="sortByRanking">true: order by rating SortKey then CommentDate, false: order by CommentDate</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId, int? coupletIndex);
|
Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId, int? coupletIndex, bool sortByRanking = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get a single comment information (replies are not included)
|
/// get a single comment information (replies are not included)
|
||||||
@ -222,6 +223,15 @@ namespace RMuseum.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<RServiceResult<GanjoorCommentSummaryViewModel>> GetCommentByIdAsync(int commentId);
|
Task<RServiceResult<GanjoorCommentSummaryViewModel>> GetCommentByIdAsync(int commentId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// like / dislike / clear rating for a comment
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="commentId"></param>
|
||||||
|
/// <param name="value">+1: like, -1: dislike, 0: remove previous rating</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<RServiceResult<bool>> RateCommentAsync(Guid userId, int commentId, short value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get a section related sections
|
/// get a section related sections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -85,8 +85,8 @@ namespace RMuseum.Services.Implementation
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var likes = await _context.GanjoorCommentReactions.AsNoTracking().Where(r => r.GanjoorCommentId == comment.Id && r.Value == 1).SumAsync(r => r.Value);
|
var likes = await _context.GanjoorCommentReactions.AsNoTracking().CountAsync(r => r.GanjoorCommentId == comment.Id && r.Value == 1);
|
||||||
var dislikes = await _context.GanjoorCommentReactions.AsNoTracking().Where(r => r.GanjoorCommentId == comment.Id && r.Value == -1).SumAsync(r => r.Value);
|
var dislikes = await _context.GanjoorCommentReactions.AsNoTracking().CountAsync(r => r.GanjoorCommentId == comment.Id && r.Value == -1);
|
||||||
comment.LikeCount = likes;
|
comment.LikeCount = likes;
|
||||||
comment.DislikeCount = dislikes;
|
comment.DislikeCount = dislikes;
|
||||||
comment.SortKey = GanjoorCommentRankingScoreCalculator.ComputeRankingScore(likes, dislikes);
|
comment.SortKey = GanjoorCommentRankingScoreCalculator.ComputeRankingScore(likes, dislikes);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user