#495 GanjoorCommentReactions
This commit is contained in:
parent
5b7e53c47c
commit
64ca7ddaa4
@ -1042,6 +1042,7 @@ namespace RMuseum.Controllers
|
|||||||
/// <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>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("poem/{id}")]
|
[Route("poem/{id}")]
|
||||||
@ -1049,10 +1050,10 @@ namespace RMuseum.Controllers
|
|||||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))]
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))]
|
||||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||||
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, bool relatedpoems = 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, bool relatedpoems = true, bool sortByRanking = true)
|
||||||
{
|
{
|
||||||
RServiceResult<GanjoorPoemCompleteViewModel> res =
|
RServiceResult<GanjoorPoemCompleteViewModel> res =
|
||||||
await _ganjoorService.GetPoemById(id, catInfo, catPoems, rhymes, recitations, images, songs, comments, verseDetails, navigation, relatedpoems);
|
await _ganjoorService.GetPoemById(id, catInfo, catPoems, rhymes, recitations, images, songs, comments, verseDetails, navigation, relatedpoems, true, sortByRanking );
|
||||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||||
return BadRequest(res.ExceptionString);
|
return BadRequest(res.ExceptionString);
|
||||||
if (res.Result == null)
|
if (res.Result == null)
|
||||||
|
|||||||
@ -669,5 +669,10 @@ namespace RMuseum.DbContext
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DbSet<GanjoorCatCorrection> GanjoorCatCorrections { get; set; }
|
public DbSet<GanjoorCatCorrection> GanjoorCatCorrections { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// comment reactions
|
||||||
|
/// </summary>
|
||||||
|
public DbSet<GanjoorCommentReaction> GanjoorCommentReactions { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,5 +76,21 @@ namespace RMuseum.Models.Ganjoor.ViewModels
|
|||||||
/// couplet summary
|
/// couplet summary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string CoupletSummary { get; set; }
|
public string CoupletSummary { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total likes
|
||||||
|
/// </summary>
|
||||||
|
public int LikeCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total dislikes
|
||||||
|
/// </summary>
|
||||||
|
public int DislikeCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// +1 = Like
|
||||||
|
/// -1 = Dislike
|
||||||
|
/// </summary>
|
||||||
|
public short CurrentUserRatingValue { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,6 +74,21 @@ namespace RMuseum.Models.Ganjoor.ViewModels
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsBookmarked { get; set; }
|
public bool IsBookmarked { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total likes
|
||||||
|
/// </summary>
|
||||||
|
public int LikeCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total dislikes
|
||||||
|
/// </summary>
|
||||||
|
public int DislikeCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// +1 = Like
|
||||||
|
/// -1 = Dislike
|
||||||
|
/// </summary>
|
||||||
|
public short CurrentUserRatingValue { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3920,6 +3920,11 @@
|
|||||||
ganjoor cat corrections
|
ganjoor cat corrections
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RMuseum.DbContext.RMuseumDbContext.GanjoorCommentReactions">
|
||||||
|
<summary>
|
||||||
|
comment reactions
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Migrations.PictureFileExtUrl">
|
<member name="T:RMuseum.Migrations.PictureFileExtUrl">
|
||||||
<inheritdoc />
|
<inheritdoc />
|
||||||
</member>
|
</member>
|
||||||
@ -11553,6 +11558,22 @@
|
|||||||
couplet summary
|
couplet summary
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentFullViewModel.LikeCount">
|
||||||
|
<summary>
|
||||||
|
Total likes
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentFullViewModel.DislikeCount">
|
||||||
|
<summary>
|
||||||
|
Total dislikes
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentFullViewModel.CurrentUserRatingValue">
|
||||||
|
<summary>
|
||||||
|
+1 = Like
|
||||||
|
-1 = Dislike
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentPostViewModel">
|
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentPostViewModel">
|
||||||
<summary>
|
<summary>
|
||||||
new comment model
|
new comment model
|
||||||
@ -11648,6 +11669,22 @@
|
|||||||
for client
|
for client
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentSummaryViewModel.LikeCount">
|
||||||
|
<summary>
|
||||||
|
Total likes
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentSummaryViewModel.DislikeCount">
|
||||||
|
<summary>
|
||||||
|
Total dislikes
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCommentSummaryViewModel.CurrentUserRatingValue">
|
||||||
|
<summary>
|
||||||
|
+1 = Like
|
||||||
|
-1 = Dislike
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel">
|
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel">
|
||||||
<summary>
|
<summary>
|
||||||
Ganjoor Couplet Number View Model
|
Ganjoor Couplet Number View Model
|
||||||
|
|||||||
@ -139,8 +139,9 @@ namespace RMuseum.Services
|
|||||||
/// <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>
|
||||||
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, bool relatedpoems = true, bool sections = 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, bool relatedpoems = true, bool sections = true, bool sortByRanking = true);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get poem verses
|
/// get poem verses
|
||||||
|
|||||||
@ -862,30 +862,44 @@ namespace RMuseum.Services.Implementation
|
|||||||
/// <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>
|
||||||
public async Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId, int? coupletIndex)
|
public async Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId, int? coupletIndex, bool sortByRanking)
|
||||||
{
|
{
|
||||||
|
var query = _context.GanjoorComments
|
||||||
|
.Include(c => c.User)
|
||||||
|
.Where(comment =>
|
||||||
|
(comment.Status == PublishStatus.Published ||
|
||||||
|
(userId != Guid.Empty &&
|
||||||
|
comment.Status == PublishStatus.Awaiting &&
|
||||||
|
comment.UserId == userId))
|
||||||
|
&&
|
||||||
|
comment.PoemId == poemId
|
||||||
|
&&
|
||||||
|
(coupletIndex == null || comment.CoupletIndex == coupletIndex));
|
||||||
|
|
||||||
|
query = sortByRanking
|
||||||
|
? query.OrderByDescending(c => c.SortKey)
|
||||||
|
.ThenByDescending(c => c.CommentDate)
|
||||||
|
: query.OrderBy(c => c.CommentDate);
|
||||||
|
|
||||||
var source =
|
var source =
|
||||||
from comment in _context.GanjoorComments.Include(c => c.User)
|
from comment in query
|
||||||
where
|
select new GanjoorCommentSummaryViewModel
|
||||||
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
|
{
|
||||||
&&
|
Id = comment.Id,
|
||||||
comment.PoemId == poemId
|
AuthorName = comment.User == null ? comment.AuthorName : comment.User.NickName,
|
||||||
&&
|
AuthorUrl = comment.AuthorUrl,
|
||||||
((coupletIndex == null) || (coupletIndex != null && comment.CoupletIndex == coupletIndex))
|
CommentDate = comment.CommentDate,
|
||||||
orderby comment.CommentDate
|
HtmlComment = comment.HtmlComment,
|
||||||
select new GanjoorCommentSummaryViewModel()
|
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
||||||
{
|
InReplyToId = comment.InReplyToId,
|
||||||
Id = comment.Id,
|
UserId = comment.UserId,
|
||||||
AuthorName = comment.User == null ? comment.AuthorName : $"{comment.User.NickName}",
|
CoupletIndex = comment.CoupletIndex ?? -1,
|
||||||
AuthorUrl = comment.AuthorUrl,
|
LikeCount = comment.LikeCount,
|
||||||
CommentDate = comment.CommentDate,
|
DislikeCount = comment.DislikeCount,
|
||||||
HtmlComment = comment.HtmlComment,
|
CurrentUserRatingValue = 0
|
||||||
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
};
|
||||||
InReplyToId = comment.InReplyToId,
|
|
||||||
UserId = comment.UserId,
|
|
||||||
CoupletIndex = comment.CoupletIndex == null ? -1 : (int)comment.CoupletIndex,
|
|
||||||
};
|
|
||||||
|
|
||||||
GanjoorCommentSummaryViewModel[] allComments = await source.AsNoTracking().ToArrayAsync();
|
GanjoorCommentSummaryViewModel[] allComments = await source.AsNoTracking().ToArrayAsync();
|
||||||
|
|
||||||
@ -943,6 +957,9 @@ namespace RMuseum.Services.Implementation
|
|||||||
InReplyToId = c.InReplyToId,
|
InReplyToId = c.InReplyToId,
|
||||||
UserId = c.UserId,
|
UserId = c.UserId,
|
||||||
CoupletIndex = c.CoupletIndex == null ? -1 : (int)c.CoupletIndex,
|
CoupletIndex = c.CoupletIndex == null ? -1 : (int)c.CoupletIndex,
|
||||||
|
LikeCount = c.LikeCount,
|
||||||
|
DislikeCount = c.DislikeCount,
|
||||||
|
CurrentUserRatingValue = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
GanjoorCommentSummaryViewModel comment = await source.AsNoTracking().SingleOrDefaultAsync();
|
GanjoorCommentSummaryViewModel comment = await source.AsNoTracking().SingleOrDefaultAsync();
|
||||||
@ -1111,10 +1128,13 @@ namespace RMuseum.Services.Implementation
|
|||||||
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
||||||
InReplyToId = comment.InReplyToId,
|
InReplyToId = comment.InReplyToId,
|
||||||
UserId = comment.UserId,
|
UserId = comment.UserId,
|
||||||
Replies = new GanjoorCommentSummaryViewModel[] { },
|
Replies = { },
|
||||||
CoupletIndex = coupletIndex == null ? -1 : (int)coupletIndex,
|
CoupletIndex = coupletIndex == null ? -1 : (int)coupletIndex,
|
||||||
MyComment = true,
|
MyComment = true,
|
||||||
CoupletSummary = _CutSummary(coupletSummary)
|
CoupletSummary = _CutSummary(coupletSummary),
|
||||||
|
LikeCount = comment.LikeCount,
|
||||||
|
DislikeCount = comment.DislikeCount,
|
||||||
|
CurrentUserRatingValue = 0,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1489,6 +1509,9 @@ namespace RMuseum.Services.Implementation
|
|||||||
PublishStatus = "",
|
PublishStatus = "",
|
||||||
UserId = comment.InReplyTo.UserId,
|
UserId = comment.InReplyTo.UserId,
|
||||||
CoupletIndex = comment.InReplyTo.CoupletIndex == null ? -1 : (int)comment.InReplyTo.CoupletIndex,
|
CoupletIndex = comment.InReplyTo.CoupletIndex == null ? -1 : (int)comment.InReplyTo.CoupletIndex,
|
||||||
|
LikeCount = comment.InReplyTo.LikeCount,
|
||||||
|
DislikeCount = comment.InReplyTo.DislikeCount,
|
||||||
|
CurrentUserRatingValue = 0,
|
||||||
},
|
},
|
||||||
Poem = new GanjoorPoemSummaryViewModel()
|
Poem = new GanjoorPoemSummaryViewModel()
|
||||||
{
|
{
|
||||||
@ -1496,7 +1519,10 @@ namespace RMuseum.Services.Implementation
|
|||||||
Title = comment.Poem.FullTitle,
|
Title = comment.Poem.FullTitle,
|
||||||
UrlSlug = comment.Poem.FullUrl,
|
UrlSlug = comment.Poem.FullUrl,
|
||||||
Excerpt = ""
|
Excerpt = ""
|
||||||
}
|
},
|
||||||
|
LikeCount = comment.LikeCount,
|
||||||
|
DislikeCount = comment.DislikeCount,
|
||||||
|
CurrentUserRatingValue = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items) paginatedResult =
|
(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items) paginatedResult =
|
||||||
@ -1619,7 +1645,10 @@ namespace RMuseum.Services.Implementation
|
|||||||
CommentDate = comment.InReplyTo.CommentDate,
|
CommentDate = comment.InReplyTo.CommentDate,
|
||||||
HtmlComment = comment.InReplyTo.HtmlComment,
|
HtmlComment = comment.InReplyTo.HtmlComment,
|
||||||
PublishStatus = "",
|
PublishStatus = "",
|
||||||
UserId = comment.InReplyTo.UserId
|
UserId = comment.InReplyTo.UserId,
|
||||||
|
LikeCount = comment.LikeCount,
|
||||||
|
DislikeCount = comment.DislikeCount,
|
||||||
|
CurrentUserRatingValue = 0,
|
||||||
},
|
},
|
||||||
Poem = new GanjoorPoemSummaryViewModel()
|
Poem = new GanjoorPoemSummaryViewModel()
|
||||||
{
|
{
|
||||||
@ -1783,10 +1812,11 @@ namespace RMuseum.Services.Implementation
|
|||||||
/// <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>
|
||||||
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, bool relatedpoems = true, bool sections = 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, bool relatedpoems = true, bool sections = true, bool sortByRanking = true)
|
||||||
{
|
{
|
||||||
var cachKey = $"GetPoemById({id}, {catInfo}, {catPoems}, {rhymes}, {recitations}, {images}, {songs}, {comments}, {verseDetails}, {navigation})";
|
var cachKey = $"GetPoemById({id}, {catInfo}, {catPoems}, {rhymes}, {recitations}, {images}, {songs}, {comments}, {verseDetails}, {navigation}, {relatedpoems}, {sections}, {sortByRanking})";
|
||||||
if (!_memoryCache.TryGetValue(cachKey, out GanjoorPoemCompleteViewModel poemViewModel))
|
if (!_memoryCache.TryGetValue(cachKey, out GanjoorPoemCompleteViewModel poemViewModel))
|
||||||
{
|
{
|
||||||
var poem = await _context.GanjoorPoems.Where(p => p.Id == id).AsNoTracking().SingleOrDefaultAsync();
|
var poem = await _context.GanjoorPoems.Where(p => p.Id == id).AsNoTracking().SingleOrDefaultAsync();
|
||||||
@ -1922,7 +1952,7 @@ namespace RMuseum.Services.Implementation
|
|||||||
|
|
||||||
if (comments)
|
if (comments)
|
||||||
{
|
{
|
||||||
var commentsRes = await GetPoemComments(id, Guid.Empty, null);
|
var commentsRes = await GetPoemComments(id, Guid.Empty, null, sortByRanking);
|
||||||
if (!string.IsNullOrEmpty(commentsRes.ExceptionString))
|
if (!string.IsNullOrEmpty(commentsRes.ExceptionString))
|
||||||
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, commentsRes.ExceptionString);
|
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, commentsRes.ExceptionString);
|
||||||
poemComments = commentsRes.Result;
|
poemComments = commentsRes.Result;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user