feat: integration cloudfile
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
@@ -8,7 +9,8 @@ namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record UpdateDocumentCommand(Guid UserId, Guid DocumentId, UpdateDocumentRequest Request) : IRequest<DocumentDto>;
|
||||
|
||||
public class UpdateDocumentHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<UpdateDocumentCommand, DocumentDto>
|
||||
public class UpdateDocumentHandler(IUnitOfWork uow, IMapper mapper, IDocumentContentStore contentStore)
|
||||
: IRequestHandler<UpdateDocumentCommand, DocumentDto>
|
||||
{
|
||||
public async Task<DocumentDto> Handle(UpdateDocumentCommand command, CancellationToken ct)
|
||||
{
|
||||
@@ -22,19 +24,31 @@ public class UpdateDocumentHandler(IUnitOfWork uow, IMapper mapper) : IRequestHa
|
||||
}
|
||||
|
||||
doc.Title = request.Title.Trim();
|
||||
if (doc.Type == DocumentType.Document)
|
||||
{
|
||||
doc.Content = request.Content;
|
||||
doc.UpdatedAt = DateTime.UtcNow;
|
||||
doc.UpdatedBy = command.UserId;
|
||||
}
|
||||
else
|
||||
{
|
||||
doc.UpdatedAt = DateTime.UtcNow;
|
||||
doc.UpdatedBy = command.UserId;
|
||||
}
|
||||
doc.UpdatedAt = DateTime.UtcNow;
|
||||
doc.UpdatedBy = command.UserId;
|
||||
|
||||
await uow.SaveChangesAsync(ct);
|
||||
return mapper.Map<DocumentDto>(doc);
|
||||
|
||||
if (doc.Type == DocumentType.Document)
|
||||
{
|
||||
await contentStore.EnsureBucketAsync(doc.ProjectId, ct);
|
||||
var bytes = Encoding.UTF8.GetBytes(request.Content ?? "");
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
await contentStore.UploadAsync(doc.ProjectId, doc.Id, "text/html; charset=utf-8", ms, ct);
|
||||
}
|
||||
|
||||
doc.ContentSize = bytes.Length;
|
||||
doc.UpdatedContentAt = DateTime.UtcNow;
|
||||
doc.ContentHash = null;
|
||||
await uow.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
var dto = mapper.Map<DocumentDto>(doc);
|
||||
if (doc.Type == DocumentType.Document)
|
||||
{
|
||||
dto.Content = request.Content;
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user