#495 GanjoorCommentReactions
This commit is contained in:
parent
5b7e53c47c
commit
64ca7ddaa4
@ -1042,6 +1042,7 @@ namespace RMuseum.Controllers
|
||||
/// <param name="verseDetails"></param>
|
||||
/// <param name="navigation">next/previous</param>
|
||||
/// <param name="relatedpoems"></param>
|
||||
/// <param name="sortByRanking"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("poem/{id}")]
|
||||
@ -1049,10 +1050,10 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[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 =
|
||||
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))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
|
||||
@ -669,5 +669,10 @@ namespace RMuseum.DbContext
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
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>
|
||||
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
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.DbContext.RMuseumDbContext.GanjoorCommentReactions">
|
||||
<summary>
|
||||
comment reactions
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Migrations.PictureFileExtUrl">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
@ -11553,6 +11558,22 @@
|
||||
couplet summary
|
||||
</summary>
|
||||
</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">
|
||||
<summary>
|
||||
new comment model
|
||||
@ -11648,6 +11669,22 @@
|
||||
for client
|
||||
</summary>
|
||||
</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">
|
||||
<summary>
|
||||
Ganjoor Couplet Number View Model
|
||||
|
||||
@ -139,8 +139,9 @@ namespace RMuseum.Services
|
||||
/// <param name="navigation"></param>
|
||||
/// <param name="relatedpoems"></param>
|
||||
/// <param name="sections"></param>
|
||||
/// <param name="sortByRanking"></param>
|
||||
/// <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>
|
||||
/// get poem verses
|
||||
|
||||
@ -862,29 +862,43 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <param name="sortByRanking"></param>
|
||||
/// <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 source =
|
||||
from comment in _context.GanjoorComments.Include(c => c.User)
|
||||
where
|
||||
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
|
||||
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) || (coupletIndex != null && comment.CoupletIndex == coupletIndex))
|
||||
orderby comment.CommentDate
|
||||
select new GanjoorCommentSummaryViewModel()
|
||||
(coupletIndex == null || comment.CoupletIndex == coupletIndex));
|
||||
|
||||
query = sortByRanking
|
||||
? query.OrderByDescending(c => c.SortKey)
|
||||
.ThenByDescending(c => c.CommentDate)
|
||||
: query.OrderBy(c => c.CommentDate);
|
||||
|
||||
var source =
|
||||
from comment in query
|
||||
select new GanjoorCommentSummaryViewModel
|
||||
{
|
||||
Id = comment.Id,
|
||||
AuthorName = comment.User == null ? comment.AuthorName : $"{comment.User.NickName}",
|
||||
AuthorName = comment.User == null ? comment.AuthorName : comment.User.NickName,
|
||||
AuthorUrl = comment.AuthorUrl,
|
||||
CommentDate = comment.CommentDate,
|
||||
HtmlComment = comment.HtmlComment,
|
||||
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
||||
InReplyToId = comment.InReplyToId,
|
||||
UserId = comment.UserId,
|
||||
CoupletIndex = comment.CoupletIndex == null ? -1 : (int)comment.CoupletIndex,
|
||||
CoupletIndex = comment.CoupletIndex ?? -1,
|
||||
LikeCount = comment.LikeCount,
|
||||
DislikeCount = comment.DislikeCount,
|
||||
CurrentUserRatingValue = 0
|
||||
};
|
||||
|
||||
GanjoorCommentSummaryViewModel[] allComments = await source.AsNoTracking().ToArrayAsync();
|
||||
@ -943,6 +957,9 @@ namespace RMuseum.Services.Implementation
|
||||
InReplyToId = c.InReplyToId,
|
||||
UserId = c.UserId,
|
||||
CoupletIndex = c.CoupletIndex == null ? -1 : (int)c.CoupletIndex,
|
||||
LikeCount = c.LikeCount,
|
||||
DislikeCount = c.DislikeCount,
|
||||
CurrentUserRatingValue = 0,
|
||||
};
|
||||
|
||||
GanjoorCommentSummaryViewModel comment = await source.AsNoTracking().SingleOrDefaultAsync();
|
||||
@ -1111,10 +1128,13 @@ namespace RMuseum.Services.Implementation
|
||||
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
||||
InReplyToId = comment.InReplyToId,
|
||||
UserId = comment.UserId,
|
||||
Replies = new GanjoorCommentSummaryViewModel[] { },
|
||||
Replies = { },
|
||||
CoupletIndex = coupletIndex == null ? -1 : (int)coupletIndex,
|
||||
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 = "",
|
||||
UserId = comment.InReplyTo.UserId,
|
||||
CoupletIndex = comment.InReplyTo.CoupletIndex == null ? -1 : (int)comment.InReplyTo.CoupletIndex,
|
||||
LikeCount = comment.InReplyTo.LikeCount,
|
||||
DislikeCount = comment.InReplyTo.DislikeCount,
|
||||
CurrentUserRatingValue = 0,
|
||||
},
|
||||
Poem = new GanjoorPoemSummaryViewModel()
|
||||
{
|
||||
@ -1496,7 +1519,10 @@ namespace RMuseum.Services.Implementation
|
||||
Title = comment.Poem.FullTitle,
|
||||
UrlSlug = comment.Poem.FullUrl,
|
||||
Excerpt = ""
|
||||
}
|
||||
},
|
||||
LikeCount = comment.LikeCount,
|
||||
DislikeCount = comment.DislikeCount,
|
||||
CurrentUserRatingValue = 0,
|
||||
};
|
||||
|
||||
(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items) paginatedResult =
|
||||
@ -1619,7 +1645,10 @@ namespace RMuseum.Services.Implementation
|
||||
CommentDate = comment.InReplyTo.CommentDate,
|
||||
HtmlComment = comment.InReplyTo.HtmlComment,
|
||||
PublishStatus = "",
|
||||
UserId = comment.InReplyTo.UserId
|
||||
UserId = comment.InReplyTo.UserId,
|
||||
LikeCount = comment.LikeCount,
|
||||
DislikeCount = comment.DislikeCount,
|
||||
CurrentUserRatingValue = 0,
|
||||
},
|
||||
Poem = new GanjoorPoemSummaryViewModel()
|
||||
{
|
||||
@ -1783,10 +1812,11 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="navigation"></param>
|
||||
/// <param name="relatedpoems"></param>
|
||||
/// <param name="sections">sections</param>
|
||||
/// <param name="sortByRanking"></param>
|
||||
/// <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))
|
||||
{
|
||||
var poem = await _context.GanjoorPoems.Where(p => p.Id == id).AsNoTracking().SingleOrDefaultAsync();
|
||||
@ -1922,7 +1952,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
if (comments)
|
||||
{
|
||||
var commentsRes = await GetPoemComments(id, Guid.Empty, null);
|
||||
var commentsRes = await GetPoemComments(id, Guid.Empty, null, sortByRanking);
|
||||
if (!string.IsNullOrEmpty(commentsRes.ExceptionString))
|
||||
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, commentsRes.ExceptionString);
|
||||
poemComments = commentsRes.Result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user