Compare commits
No commits in common. "03959f9b3882267620e51bf577acbde16e5ff5f6" and "a24db1716fa7152f2d0cff70c43e2e5385a13cb8" have entirely different histories.
03959f9b38
...
a24db1716f
@ -327,7 +327,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("list/versions/{parentAttachmentId}")]
|
[HttpGet("list/versions/{parentAttachmentId}")]
|
||||||
public async Task<IActionResult> GetListAllVersionsAsync(Guid parentAttachmentId)
|
public async Task<IActionResult> GetAllVersionsAsync(Guid parentAttachmentId)
|
||||||
{
|
{
|
||||||
_logger.LogInfo("Start fetching document versions for ParentAttachmentId: {ParentAttachmentId}", parentAttachmentId);
|
_logger.LogInfo("Start fetching document versions for ParentAttachmentId: {ParentAttachmentId}", parentAttachmentId);
|
||||||
|
|
||||||
@ -379,41 +379,6 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("get/version/{id}")]
|
|
||||||
public async Task<IActionResult> GetAllVersionsAsync(Guid id)
|
|
||||||
{
|
|
||||||
// API endpoint to get all versions of an attachment by its ID
|
|
||||||
_logger.LogInfo($"Fetching versions for attachment with ID: {id}");
|
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
|
||||||
// Create a new DbContext from the factory asynchronously
|
|
||||||
using var scope = _serviceScope.CreateScope();
|
|
||||||
// Create a new service scope for scoped services
|
|
||||||
|
|
||||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
||||||
// Get the currently logged in employee asynchronously
|
|
||||||
|
|
||||||
var versionMapping = await _context.AttachmentVersionMappings
|
|
||||||
// Retrieve version mapping including the child attachment and its document
|
|
||||||
.Include(av => av.ChildAttachment)
|
|
||||||
.ThenInclude(da => da!.Document)
|
|
||||||
.FirstOrDefaultAsync(av => av.ChildAttachmentId == id);
|
|
||||||
|
|
||||||
if (versionMapping == null || versionMapping.ChildAttachment == null || versionMapping.ChildAttachment.Document == null)
|
|
||||||
// Return 404 if no version mapping or related entities found
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Version mapping not found for attachment ID: {id}");
|
|
||||||
return NotFound(ApiResponse<object>.ErrorResponse("Version not found", "Version not found in database", 404));
|
|
||||||
}
|
|
||||||
|
|
||||||
var s3Service = scope.ServiceProvider.GetRequiredService<S3UploadService>();
|
|
||||||
// Resolve S3UploadService from the scope to generate pre-signed URL
|
|
||||||
var preSignedUrl = s3Service.GeneratePreSignedUrl(versionMapping.ChildAttachment.Document.S3Key);
|
|
||||||
// Generate pre-signed URL for the document stored in S3
|
|
||||||
_logger.LogInfo($"Generated pre-signed URL for attachment ID: {id}");
|
|
||||||
|
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(preSignedUrl, "Pre-Signed Url for old version fetched successfully", 200));
|
|
||||||
// Return the pre-signed URL with a success response
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user