From 4d83091c5c80adfc2fdac93615999c61fc5cacf9 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Tue, 13 May 2025 11:17:58 +0800 Subject: [PATCH 1/2] 1 --- Yes.Application/Admins/Articles/GetArticleQueryHandler.cs | 2 +- .../Admins/Articles/GetLatestArticlesQueryHandler.cs | 2 +- Yes.Application/Admins/Pages/GetPageQueryHandler.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Yes.Application/Admins/Articles/GetArticleQueryHandler.cs b/Yes.Application/Admins/Articles/GetArticleQueryHandler.cs index bb6f7b0..b72019f 100644 --- a/Yes.Application/Admins/Articles/GetArticleQueryHandler.cs +++ b/Yes.Application/Admins/Articles/GetArticleQueryHandler.cs @@ -21,7 +21,7 @@ public async Task Handle(GetArticleQuery request, CancellationToken cancellationToken) { var article = await _db.Articles.FindAsync(request.Id); - if (article == null) + if (article == null|| article.Status== ArticleStatusEnum.Deleted) { throw new ArticleNotExistsException(request.Id); } diff --git a/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs b/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs index 6615c9b..8bc3475 100644 --- a/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs +++ b/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs @@ -15,7 +15,7 @@ private readonly BlogDbContext _db = db; public async Task> Handle(GetLatestArticlesQuery request, CancellationToken cancellationToken) { - var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article).OrderByDescending(x => x.Id).Select(article => + var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Id).Select(article => new GetLatestArticlesQueryResponse( article.Id, article.Title, diff --git a/Yes.Application/Admins/Pages/GetPageQueryHandler.cs b/Yes.Application/Admins/Pages/GetPageQueryHandler.cs index 20f59af..054ab19 100644 --- a/Yes.Application/Admins/Pages/GetPageQueryHandler.cs +++ b/Yes.Application/Admins/Pages/GetPageQueryHandler.cs @@ -22,7 +22,7 @@ public async Task Handle(GetPageQuery request, CancellationToken cancellationToken) { var page = await _db.Articles.FindAsync(request.Id); - if (page == null) + if (page == null || page.Status == ArticleStatusEnum.Deleted) { throw new PageNotExistsException(request.Id); } From c81f267eccfeacb8c925fc44bb3800721b3107fd Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Tue, 13 May 2025 11:27:58 +0800 Subject: [PATCH 2/2] 1 --- Yes.Application/Admins/Articles/ArticleService.cs | 2 +- .../Admins/Articles/DeleteArticleCommandHandler.cs | 2 +- .../Admins/Articles/GetLatestArticlesQueryHandler.cs | 2 +- .../Admins/Articles/UpdateArticleCommandHandler.cs | 2 +- Yes.Application/Admins/Articles/UpdateDraftCommandHandler.cs | 2 +- Yes.Application/Admins/Categories/CategorieService.cs | 2 +- .../Admins/Categories/DeleteCategoryCommandHandler.cs | 2 +- Yes.Application/Blogs/BlogService.cs | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Yes.Application/Admins/Articles/ArticleService.cs b/Yes.Application/Admins/Articles/ArticleService.cs index 5bc220e..7fba7a2 100644 --- a/Yes.Application/Admins/Articles/ArticleService.cs +++ b/Yes.Application/Admins/Articles/ArticleService.cs @@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Articles private readonly BlogDbContext _db = db; public async Task IsSlugInUse(string slug) { - return await _db.Articles.AnyAsync(x => x.Slug == slug); + return await _db.Articles.AnyAsync(x => x.Slug == slug && x.Status!= ArticleStatusEnum.Deleted); } public async Task CreateUniqueSlug() diff --git a/Yes.Application/Admins/Articles/DeleteArticleCommandHandler.cs b/Yes.Application/Admins/Articles/DeleteArticleCommandHandler.cs index 033c139..73ce40f 100644 --- a/Yes.Application/Admins/Articles/DeleteArticleCommandHandler.cs +++ b/Yes.Application/Admins/Articles/DeleteArticleCommandHandler.cs @@ -14,7 +14,7 @@ public async Task Handle(DeleteArticleCommand request, CancellationToken cancellationToken) { var article = await _db.Articles.FindAsync(request.Id); - if (article != null) + if (article != null && article.Status!= ArticleStatusEnum.Deleted) { var identityUser = await _db.Users.FindAsync(_identity.Id); if (identityUser == null) diff --git a/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs b/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs index 8bc3475..53900af 100644 --- a/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs +++ b/Yes.Application/Admins/Articles/GetLatestArticlesQueryHandler.cs @@ -15,7 +15,7 @@ private readonly BlogDbContext _db = db; public async Task> Handle(GetLatestArticlesQuery request, CancellationToken cancellationToken) { - var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Id).Select(article => + var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article && x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Id).Select(article => new GetLatestArticlesQueryResponse( article.Id, article.Title, diff --git a/Yes.Application/Admins/Articles/UpdateArticleCommandHandler.cs b/Yes.Application/Admins/Articles/UpdateArticleCommandHandler.cs index 117b0cb..bcbaf99 100644 --- a/Yes.Application/Admins/Articles/UpdateArticleCommandHandler.cs +++ b/Yes.Application/Admins/Articles/UpdateArticleCommandHandler.cs @@ -36,7 +36,7 @@ var categoryObject = ValueObject.Create(request.CategoryId, category); var article = await _db.Articles.FindAsync(request.Id); - if (article == null) + if (article == null|| article.Status == ArticleStatusEnum.Deleted) { throw new ArticleNotExistsException(request.Id); } diff --git a/Yes.Application/Admins/Articles/UpdateDraftCommandHandler.cs b/Yes.Application/Admins/Articles/UpdateDraftCommandHandler.cs index f2d1389..64059ea 100644 --- a/Yes.Application/Admins/Articles/UpdateDraftCommandHandler.cs +++ b/Yes.Application/Admins/Articles/UpdateDraftCommandHandler.cs @@ -30,7 +30,7 @@ var categoryObject = ValueObject.Create(request.CategoryId, category); var article = await _db.Articles.FindAsync(request.Id); - if (article == null) + if (article == null || article.Status == ArticleStatusEnum.Deleted) { throw new ArticleNotExistsException(request.Id); } diff --git a/Yes.Application/Admins/Categories/CategorieService.cs b/Yes.Application/Admins/Categories/CategorieService.cs index 8eea6b5..fa2c06f 100644 --- a/Yes.Application/Admins/Categories/CategorieService.cs +++ b/Yes.Application/Admins/Categories/CategorieService.cs @@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Categories private readonly BlogDbContext _db = db; public async Task IsSlugInUse(string slug) { - return await _db.Articles.AnyAsync(x => x.Slug == slug); + return await _db.Articles.AnyAsync(x => x.Slug == slug && x.Status != ArticleStatusEnum.Deleted); } public async Task EnsureSlug() diff --git a/Yes.Application/Admins/Categories/DeleteCategoryCommandHandler.cs b/Yes.Application/Admins/Categories/DeleteCategoryCommandHandler.cs index 5d79830..7819168 100644 --- a/Yes.Application/Admins/Categories/DeleteCategoryCommandHandler.cs +++ b/Yes.Application/Admins/Categories/DeleteCategoryCommandHandler.cs @@ -22,7 +22,7 @@ throw new AccessDeniedException(); } - var hasArticlesInCategory = await _db.Articles.AnyAsync(x => x.CategoryId == request.Id, cancellationToken); + var hasArticlesInCategory = await _db.Articles.AnyAsync(x => x.CategoryId == request.Id && x.Status!= ArticleStatusEnum.Deleted, cancellationToken); if (hasArticlesInCategory) { throw new DeleteCategoryException("分类下还有文章,无法删除!"); diff --git a/Yes.Application/Blogs/BlogService.cs b/Yes.Application/Blogs/BlogService.cs index 869a7c1..4097908 100644 --- a/Yes.Application/Blogs/BlogService.cs +++ b/Yes.Application/Blogs/BlogService.cs @@ -422,7 +422,7 @@ { x.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10); - var articles = _db.Articles.Where(x => x.Type == ArticleTypeEnum.Page).OrderByDescending(x => x.Sort).Take(top).Select(x => x.ArticleEntityToSinglePage()).ToList(); + var articles = _db.Articles.Where(x => x.Type == ArticleTypeEnum.Page && x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Sort).Take(top).Select(x => x.ArticleEntityToSinglePage()).ToList(); articles.ForEach(x => { @@ -441,7 +441,7 @@ { articleEntity = await _db.Articles.FirstOrDefaultAsync(x => x.Slug == slug); } - if (articleEntity == null) + if (articleEntity == null || articleEntity.Status == ArticleStatusEnum.Deleted) { throw new PageNotFoundException(); }