From e27a27a073ce6374cd19c269bf076ba4a4065098 Mon Sep 17 00:00:00 2001 From: IGeekFan Date: Sat, 18 May 2024 14:51:18 +0800 Subject: [PATCH] add user like article query --- .../Blog/Articles/ArticleSearchDto.cs | 10 ++++++++ .../LinCms.Application.Contracts.xml | 5 ++++ .../Blog/Articles/ArticleService.cs | 23 +++++++++++++++---- .../Blog/AuthorCenter/AuthorCenterService.cs | 5 +--- src/LinCms.Web/LinCms.Web.xml | 5 ++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/LinCms.Application.Contracts/Blog/Articles/ArticleSearchDto.cs b/src/LinCms.Application.Contracts/Blog/Articles/ArticleSearchDto.cs index 6be59165..48a6a262 100644 --- a/src/LinCms.Application.Contracts/Blog/Articles/ArticleSearchDto.cs +++ b/src/LinCms.Application.Contracts/Blog/Articles/ArticleSearchDto.cs @@ -19,9 +19,19 @@ public class ArticleSearchDto : PageDto /// public Guid? CollectionId { get; set; } + public ArticleSearchTypeEnum? ArticleSearchType { get; set; } public override string ToString() { return $"{ClassifyId}:{ChannelId}:{TagId}:{Title}:{UserId}:{Count}:{Page}:{Sort}"; } +} + + +public enum ArticleSearchTypeEnum +{ + /// + /// 点赞 + /// + Like, } \ No newline at end of file diff --git a/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml b/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml index 97b2fb81..117cabbb 100644 --- a/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml +++ b/src/LinCms.Application.Contracts/LinCms.Application.Contracts.xml @@ -44,6 +44,11 @@ 收藏集合Id + + + 点赞 + + 得到我关注的人发布的随笔 diff --git a/src/LinCms.Application/Blog/Articles/ArticleService.cs b/src/LinCms.Application/Blog/Articles/ArticleService.cs index e4f4e9a7..ac7a2c78 100644 --- a/src/LinCms.Application/Blog/Articles/ArticleService.cs +++ b/src/LinCms.Application/Blog/Articles/ArticleService.cs @@ -38,6 +38,7 @@ public class ArticleService(IAuditBaseRepository
articleRepository, #region CRUD + /// public async Task> GetArticleAsync(ArticleSearchDto searchDto) { DateTime monthDays = DateTime.Now.AddDays(-30); @@ -60,6 +61,18 @@ public async Task> GetArticleAsync(ArticleSearchD } long? userId = CurrentUser.FindUserId(); + + List likedArticleIds = new(); + bool isAnyLiked = false; + + if (searchDto.ArticleSearchType == ArticleSearchTypeEnum.Like) + { + likedArticleIds = await userLikeRepository.Select + .Where(r => r.CreateUserId == userId && r.SubjectType == UserLikeSubjectType.UserLikeArticle) + .ToListAsync(r => r.SubjectId); + isAnyLiked = searchDto.ArticleSearchType == ArticleSearchTypeEnum.Like && likedArticleIds.Any(); + } + List
articles = await articleRepository .Select .Include(r => r.UserInfo) @@ -76,12 +89,14 @@ public async Task> GetArticleAsync(ArticleSearchD .WhereIf(searchDto.Sort == "WEEKLY_HOTTEST", r => r.CreateTime > weeklyDays) .WhereIf(searchDto.Sort == "MONTHLY_HOTTEST", r => r.CreateTime > monthDays) .WhereIf(searchDto.CollectionId != null, r => articleIds.Contains(r.Id)) + .WhereIf(isAnyLiked, r => likedArticleIds.Contains(r.Id)) .OrderByDescending( searchDto.Sort == "THREE_DAYS_HOTTEST" || searchDto.Sort == "WEEKLY_HOTTEST" || searchDto.Sort == "MONTHLY_HOTTEST" || searchDto.Sort == "HOTTEST", r => r.ViewHits + (r.LikesQuantity * 20) + (r.CommentQuantity * 30)) - .OrderByDescending(r => r.CreateTime).ToPagerListAsync(searchDto, out long totalCount); + .OrderByDescending(r => r.CreateTime) + .ToPagerListAsync(searchDto, out long totalCount); List articleDtos = articles .Select(a => @@ -111,7 +126,7 @@ public async Task DeleteAsync(Guid id) } } - await articleRepository.DeleteAsync(new Article { Id = id }); + await articleRepository.DeleteAsync(new Article {Id = id}); await tagArticleRepository.DeleteAsync(r => r.ArticleId == id); await commentRepository.DeleteAsync(r => r.SubjectId == id); await userLikeRepository.DeleteAsync(r => r.SubjectId == id); @@ -160,7 +175,7 @@ public async Task CreateAsync(CreateUpdateArticleDto createArticle) Article article = Mapper.Map
(createArticle); article.Archive = DateTime.Now.ToString("yyy年MM月"); article.WordNumber = createArticle.Content.Length; - article.ReadingTime = (long)TextAnalysisUtil.GetReadingTime(createArticle.Content).Minutes; + article.ReadingTime = (long) TextAnalysisUtil.GetReadingTime(createArticle.Content).Minutes; article.Tags = new List(); foreach (var articleTagId in createArticle.TagIds) @@ -209,7 +224,7 @@ public async Task UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto) Mapper.Map(updateArticleDto, article); article.WordNumber = article.Content.Length; - article.ReadingTime = (long)TextAnalysisUtil.GetReadingTime(article.Content).Minutes; + article.ReadingTime = (long) TextAnalysisUtil.GetReadingTime(article.Content).Minutes; await articleRepository.UpdateAsync(article); ArticleDraft articleDraft = Mapper.Map(article); diff --git a/src/LinCms.Application/Blog/AuthorCenter/AuthorCenterService.cs b/src/LinCms.Application/Blog/AuthorCenter/AuthorCenterService.cs index f2161e38..aa493967 100644 --- a/src/LinCms.Application/Blog/AuthorCenter/AuthorCenterService.cs +++ b/src/LinCms.Application/Blog/AuthorCenter/AuthorCenterService.cs @@ -9,12 +9,9 @@ namespace LinCms.Blog.AuthorCenter /// 创建者中心统计 ///
public class AuthorCenterService(IAuditBaseRepository
articleRepository, - IAuditBaseRepository userLikeRepository, - IAuditBaseRepository commentRepository) + IAuditBaseRepository userLikeRepository) : ApplicationService, IAuthorCenterService { - private readonly IAuditBaseRepository _commentRepository = commentRepository; - public async Task GetArtcileCardAsync() { long? userid = CurrentUser.FindUserId(); diff --git a/src/LinCms.Web/LinCms.Web.xml b/src/LinCms.Web/LinCms.Web.xml index 284212d8..bb3bbe0b 100644 --- a/src/LinCms.Web/LinCms.Web.xml +++ b/src/LinCms.Web/LinCms.Web.xml @@ -831,6 +831,11 @@ 七牛云上传服务 + + + 七牛云上传服务 + + 将掘金中的取所有标签存到七牛云上,基本信息存入数据库