| 1234567891011121314151617181920212223242526272829303132333435 |
- 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<Command, Result<Response>>
- {
- public async Task<Result<Response>> 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<Response>(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);
- }
- }
|