| 12345678910111213141516171819202122232425262728 |
- using Application.Abstractions.Messaging;
- using Application.Abstractions.Data;
- using SharedKernel.Results;
- using SharedKernel.Storage;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Admin.Forum.Post.DeleteThumbnail;
- public sealed class Handler(IAppDbContext db, IFileStorage fileStorage) : ICommandHandler<Command, Result>
- {
- public async Task<Result> Handle(Command request, CancellationToken ct)
- {
- var post = await db.Post.FirstOrDefaultAsync(x => x.ID == request.ID, ct);
- if (post is null)
- {
- return Result.Failure(Error.NotFound("Post.NotFound", "게시글을 찾을 수 없습니다."));
- }
- if (!string.IsNullOrEmpty(post.Thumbnail))
- {
- fileStorage.DeleteByUrl(post.Thumbnail);
- post.Thumbnail = null;
- await db.SaveChangesAsync(ct);
- }
- return Result.Success();
- }
- }
|