using Application.Abstractions.Messaging; using Application.Abstractions.Data; using Domain.Entities.Forum.Logs; using SharedKernel.Results; using Microsoft.EntityFrameworkCore; namespace Application.Features.Api.Forum.PostFile.Download; public sealed class Handler(IAppDbContext db) : ICommandHandler> { public async Task> Handle(Command request, CancellationToken ct) { var file = await db.PostFile.FirstOrDefaultAsync(x => x.ID == request.PostFileID && !x.IsDisabled, ct); if (file is null) { return Result.Failure(Error.NotFound("PostFile.NotFound", "파일을 찾을 수 없습니다.")); } file.Downloads++; var log = new PostFileDownLog { PostID = file.PostID, PostFileID = file.ID, MemberID = request.MemberID, IpAddress = request.IpAddress, UserAgent = request.UserAgent }; await db.PostFileDownLog.AddAsync(log, ct); await db.SaveChangesAsync(ct); return new Response(file.Url, file.FileName); } }