Merge branch 'release' into 'master'
Release See merge request yescent/yes.blog!62
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Articles
|
|||||||
private readonly BlogDbContext _db = db;
|
private readonly BlogDbContext _db = db;
|
||||||
public async Task<bool> IsSlugInUse(string slug)
|
public async Task<bool> 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<string> CreateUniqueSlug()
|
public async Task<string> CreateUniqueSlug()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
public async Task<DeleteArticleCommandResponse> Handle(DeleteArticleCommand request, CancellationToken cancellationToken)
|
public async Task<DeleteArticleCommandResponse> Handle(DeleteArticleCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var article = await _db.Articles.FindAsync(request.Id);
|
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);
|
var identityUser = await _db.Users.FindAsync(_identity.Id);
|
||||||
if (identityUser == null)
|
if (identityUser == null)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
public async Task<GetArticleQueryResponse> Handle(GetArticleQuery request, CancellationToken cancellationToken)
|
public async Task<GetArticleQueryResponse> Handle(GetArticleQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var article = await _db.Articles.FindAsync(request.Id);
|
var article = await _db.Articles.FindAsync(request.Id);
|
||||||
if (article == null)
|
if (article == null|| article.Status== ArticleStatusEnum.Deleted)
|
||||||
{
|
{
|
||||||
throw new ArticleNotExistsException(request.Id);
|
throw new ArticleNotExistsException(request.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
private readonly BlogDbContext _db = db;
|
private readonly BlogDbContext _db = db;
|
||||||
public async Task<List<GetLatestArticlesQueryResponse>> Handle(GetLatestArticlesQuery request, CancellationToken cancellationToken)
|
public async Task<List<GetLatestArticlesQueryResponse>> 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(
|
new GetLatestArticlesQueryResponse(
|
||||||
article.Id,
|
article.Id,
|
||||||
article.Title,
|
article.Title,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
||||||
|
|
||||||
var article = await _db.Articles.FindAsync(request.Id);
|
var article = await _db.Articles.FindAsync(request.Id);
|
||||||
if (article == null)
|
if (article == null|| article.Status == ArticleStatusEnum.Deleted)
|
||||||
{
|
{
|
||||||
throw new ArticleNotExistsException(request.Id);
|
throw new ArticleNotExistsException(request.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
||||||
|
|
||||||
var article = await _db.Articles.FindAsync(request.Id);
|
var article = await _db.Articles.FindAsync(request.Id);
|
||||||
if (article == null)
|
if (article == null || article.Status == ArticleStatusEnum.Deleted)
|
||||||
{
|
{
|
||||||
throw new ArticleNotExistsException(request.Id);
|
throw new ArticleNotExistsException(request.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Categories
|
|||||||
private readonly BlogDbContext _db = db;
|
private readonly BlogDbContext _db = db;
|
||||||
public async Task<bool> IsSlugInUse(string slug)
|
public async Task<bool> 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<string> EnsureSlug()
|
public async Task<string> EnsureSlug()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
throw new AccessDeniedException();
|
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)
|
if (hasArticlesInCategory)
|
||||||
{
|
{
|
||||||
throw new DeleteCategoryException("分类下还有文章,无法删除!");
|
throw new DeleteCategoryException("分类下还有文章,无法删除!");
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
public async Task<GetPageQueryResponse> Handle(GetPageQuery request, CancellationToken cancellationToken)
|
public async Task<GetPageQueryResponse> Handle(GetPageQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var page = await _db.Articles.FindAsync(request.Id);
|
var page = await _db.Articles.FindAsync(request.Id);
|
||||||
if (page == null)
|
if (page == null || page.Status == ArticleStatusEnum.Deleted)
|
||||||
{
|
{
|
||||||
throw new PageNotExistsException(request.Id);
|
throw new PageNotExistsException(request.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,7 +422,7 @@
|
|||||||
{
|
{
|
||||||
x.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
|
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 =>
|
articles.ForEach(x =>
|
||||||
{
|
{
|
||||||
@@ -441,7 +441,7 @@
|
|||||||
{
|
{
|
||||||
articleEntity = await _db.Articles.FirstOrDefaultAsync(x => x.Slug == slug);
|
articleEntity = await _db.Articles.FirstOrDefaultAsync(x => x.Slug == slug);
|
||||||
}
|
}
|
||||||
if (articleEntity == null)
|
if (articleEntity == null || articleEntity.Status == ArticleStatusEnum.Deleted)
|
||||||
{
|
{
|
||||||
throw new PageNotFoundException();
|
throw new PageNotFoundException();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user