This commit is contained in:
2025-05-11 00:14:12 +08:00
parent ef9227cc01
commit 1275bed033
2 changed files with 22 additions and 6 deletions

View File

@@ -1,18 +1,36 @@
namespace Yes.Application.Admins.Articles namespace Yes.Application.Admins.Articles
{ {
public record DeleteArticleCommand(int Id) : IRequest<DeleteArticleCommandResponse>; public record DeleteArticleCommand(int Id) : IRequest<DeleteArticleCommandResponse>;
public record DeleteArticleCommandResponse(int Id); public record DeleteArticleCommandResponse(int Id);
public class DeleteArticleCommandHandler(BlogDbContext db) : IRequestHandler<DeleteArticleCommand, DeleteArticleCommandResponse> public class DeleteArticleCommandHandler(
BlogDbContext db,
IIdentityContext identity) : IRequestHandler<DeleteArticleCommand, DeleteArticleCommandResponse>
{ {
private readonly BlogDbContext _db = db; private readonly BlogDbContext _db = db;
private readonly IIdentityContext _identity = identity;
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)
{ {
var identityUser = await _db.Users.FindAsync(_identity.Id);
if (identityUser == null)
{
throw new UserNotExistsException(_identity.Id);
}
if (!identityUser.IsSystemUser())
{
if (article.UserId != identityUser.Id)
{
throw new AccessDeniedException();
}
}
article.Delete(); article.Delete();
_db.Articles.Update(article); _db.Articles.Update(article);
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();

View File

@@ -1,6 +1,4 @@
using static Dapper.SqlMapper; namespace Yes.Application.Admins.Configurations
namespace Yes.Application.Admins.Configurations
{ {
public record UpdateConfigurationCommand( public record UpdateConfigurationCommand(
string Name, string Name,