bug section completed
This commit is contained in:
@@ -18,19 +18,17 @@ public class CreateBugSectionCommandHandler : IBaseCommandHandler<CreateBugSecti
|
||||
{
|
||||
readonly IUnitOfWork _unitOfWork;
|
||||
readonly IBugSectionRepository _bugSectionRepository;
|
||||
readonly IUploadedFileRepository _uploadedFileRepository;
|
||||
private readonly IFileStorageService _fileStorageService;
|
||||
private readonly IThumbnailGeneratorService _thumbnailService;
|
||||
readonly IFileUploadService _fileUploadService;
|
||||
private readonly IAuthHelper _authHelper;
|
||||
|
||||
public CreateBugSectionCommandHandler(IUnitOfWork unitOfWork, IBugSectionRepository bugSectionRepository, IUploadedFileRepository uploadedFileRepository, IAuthHelper authHelper, IFileStorageService fileStorageService, IThumbnailGeneratorService thumbnailService)
|
||||
public CreateBugSectionCommandHandler(IUnitOfWork unitOfWork, IBugSectionRepository bugSectionRepository,
|
||||
IAuthHelper authHelper, IFileUploadService fileUploadService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_bugSectionRepository = bugSectionRepository;
|
||||
_uploadedFileRepository = uploadedFileRepository;
|
||||
|
||||
_authHelper = authHelper;
|
||||
_fileStorageService = fileStorageService;
|
||||
_thumbnailService = thumbnailService;
|
||||
_fileUploadService = fileUploadService;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> Handle(CreateBugSectionCommand request, CancellationToken cancellationToken)
|
||||
@@ -57,65 +55,17 @@ public class CreateBugSectionCommandHandler : IBaseCommandHandler<CreateBugSecti
|
||||
{
|
||||
foreach (var file in request.Files)
|
||||
{
|
||||
const long maxFileSize = 100 * 1024 * 1024;
|
||||
if (file.Length > maxFileSize)
|
||||
return OperationResult.Failure("حجم فایل بیش از حد مجاز است (حداکثر 100MB)");
|
||||
|
||||
var fileType = DetectFileType(file.ContentType, Path.GetExtension(file.FileName));
|
||||
|
||||
var uploadedFile = new UploadedFile(
|
||||
originalFileName: file.FileName,
|
||||
fileSizeBytes: file.Length,
|
||||
mimeType: file.ContentType,
|
||||
fileType: fileType,
|
||||
category: FileCategory.TaskChatMessage,
|
||||
uploadedByUserId: currentUserId,
|
||||
storageProvider: StorageProvider.LocalFileSystem
|
||||
var uploadedFile = await _fileUploadService.UploadFileAsync
|
||||
(
|
||||
file,
|
||||
FileCategory.BugSection,
|
||||
currentUserId
|
||||
);
|
||||
|
||||
await _uploadedFileRepository.AddAsync(uploadedFile);
|
||||
|
||||
|
||||
try
|
||||
if (!uploadedFile.IsSuccess)
|
||||
{
|
||||
using var stream = file.OpenReadStream();
|
||||
var uploadResult = await _fileStorageService.UploadAsync(
|
||||
stream,
|
||||
uploadedFile.UniqueFileName,
|
||||
"TaskChatMessage"
|
||||
);
|
||||
|
||||
uploadedFile.CompleteUpload(uploadResult.StoragePath, uploadResult.StorageUrl);
|
||||
|
||||
if (fileType == FileType.Image)
|
||||
{
|
||||
var dimensions = await _thumbnailService.GetImageDimensionsAsync(uploadResult.StoragePath);
|
||||
if (dimensions.HasValue)
|
||||
{
|
||||
uploadedFile.SetImageDimensions(dimensions.Value.Width, dimensions.Value.Height);
|
||||
}
|
||||
|
||||
var thumbnail = await _thumbnailService
|
||||
.GenerateImageThumbnailAsync(uploadResult.StoragePath, category: "TaskChatMessage");
|
||||
if (thumbnail.HasValue)
|
||||
{
|
||||
uploadedFile.SetThumbnail(thumbnail.Value.ThumbnailUrl);
|
||||
}
|
||||
}
|
||||
|
||||
await _uploadedFileRepository.UpdateAsync(uploadedFile);
|
||||
|
||||
|
||||
return OperationResult.Failure(uploadedFile.ErrorMessage ?? "خطا در آپلود فایل");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _uploadedFileRepository.DeleteAsync(uploadedFile);
|
||||
|
||||
|
||||
return OperationResult<MessageDto>.ValidationError($"خطا در آپلود فایل: {ex.Message}");
|
||||
}
|
||||
|
||||
bug.AddDocument(new BugDocument(uploadedFile.Id));
|
||||
bug.AddDocument(new BugDocument(uploadedFile.FileId!.Value));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -124,22 +74,7 @@ public class CreateBugSectionCommandHandler : IBaseCommandHandler<CreateBugSecti
|
||||
return OperationResult.Success();
|
||||
}
|
||||
|
||||
private FileType DetectFileType(string mimeType, string extension)
|
||||
{
|
||||
if (mimeType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
|
||||
return FileType.Image;
|
||||
|
||||
if (mimeType.StartsWith("video/", StringComparison.OrdinalIgnoreCase))
|
||||
return FileType.Video;
|
||||
|
||||
if (mimeType.StartsWith("audio/", StringComparison.OrdinalIgnoreCase))
|
||||
return FileType.Audio;
|
||||
|
||||
if (new[] { ".zip", ".rar", ".7z", ".tar", ".gz" }.Contains(extension.ToLower()))
|
||||
return FileType.Archive;
|
||||
|
||||
return FileType.Document;
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateBugSectionCommand(Guid TaskId, string InitialDescription, long OriginalAssignedUserId, ProjectTaskPriority Priority, List<IFormFile> Files) : IBaseCommand;
|
||||
|
||||
@@ -15,15 +15,15 @@ public class GetBugModalDetailsQueryHandler : IBaseQueryHandler<GetBugModalDetai
|
||||
|
||||
public async Task<OperationResult<GetBugModalDetailsResponse>> Handle(GetBugModalDetailsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var projectTask =await _context.ProjectTasks.FirstOrDefaultAsync(x=>x.Id == request.TaskId);
|
||||
var projectTask =await _context.ProjectTasks.Include(ph=>ph.Phase).ThenInclude(p=>p.Project).FirstOrDefaultAsync(x=>x.Id == request.TaskId);
|
||||
if(projectTask == null)
|
||||
return OperationResult<GetBugModalDetailsResponse>.NotFound("کاربر یافت نشد");
|
||||
return OperationResult<GetBugModalDetailsResponse>.NotFound("بخش یافت نشد");
|
||||
|
||||
var response = new GetBugModalDetailsResponse(projectTask.Name);
|
||||
var response = new GetBugModalDetailsResponse(projectTask.Name,projectTask.Phase.Name, projectTask.Phase.Project.Name);
|
||||
return OperationResult<GetBugModalDetailsResponse>.Success(response);
|
||||
}
|
||||
}
|
||||
|
||||
public record GetBugModalDetailsQuery(Guid TaskId) : IBaseQuery<GetBugModalDetailsResponse>;
|
||||
|
||||
public record GetBugModalDetailsResponse(string Name);
|
||||
public record GetBugModalDetailsResponse(string TaskName, string PhaseName, string ProjectName);
|
||||
@@ -10,6 +10,7 @@ public enum FileCategory
|
||||
ProjectDocument = 3, // مستندات پروژه
|
||||
UserProfilePhoto = 4, // عکس پروفایل کاربر
|
||||
Report = 5, // گزارش
|
||||
Other = 6 // سایر
|
||||
Other = 6, // سایر
|
||||
BugSection = 7, // تسک باگ
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ public class FileUploadService : IFileUploadService
|
||||
await _fileRepository.SaveChangesAsync();
|
||||
|
||||
// آپلود فایل به استوریج
|
||||
var categoryFolder = GetCategoryFolderName(category);
|
||||
var categoryFolder = category.ToString();
|
||||
var uploadResult = await _fileStorageService.UploadAsync(
|
||||
fileStream,
|
||||
uploadedFile.UniqueFileName,
|
||||
@@ -228,20 +228,5 @@ public class FileUploadService : IFileUploadService
|
||||
return FileType.Document;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت نام پوشه بر اساس دستهبندی
|
||||
/// </summary>
|
||||
private string GetCategoryFolderName(FileCategory category)
|
||||
{
|
||||
return category switch
|
||||
{
|
||||
FileCategory.TaskChatMessage => "TaskChatMessage",
|
||||
FileCategory.TaskAttachment => "TaskAttachment",
|
||||
FileCategory.ProjectDocument => "ProjectDocument",
|
||||
FileCategory.UserProfilePhoto => "UserProfilePhoto",
|
||||
FileCategory.Report => "Report",
|
||||
_ => "Other"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user