feat(applications): preserve submitted packages
This commit is contained in:
@@ -23,11 +23,13 @@ public sealed class ApplicationAssetsController : ControllerBase
|
||||
|
||||
private readonly UserManager<ApplicationUser> _users;
|
||||
private readonly IApplicationAssetsService _assets;
|
||||
private readonly ISubmittedApplicationPackageService _packages;
|
||||
|
||||
public ApplicationAssetsController(UserManager<ApplicationUser> users, IApplicationAssetsService assets)
|
||||
public ApplicationAssetsController(UserManager<ApplicationUser> users, IApplicationAssetsService assets, ISubmittedApplicationPackageService packages)
|
||||
{
|
||||
_users = users;
|
||||
_assets = assets;
|
||||
_packages = packages;
|
||||
}
|
||||
|
||||
[HttpGet("cv")]
|
||||
@@ -85,5 +87,50 @@ public sealed class ApplicationAssetsController : ControllerBase
|
||||
return result is null ? NotFound() : Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("submitted-packages")]
|
||||
public async Task<ActionResult<IReadOnlyList<SubmittedPackageDto>>> ListSubmittedPackages(int jobId, CancellationToken ct)
|
||||
{
|
||||
var userId = await CurrentUserIdAsync();
|
||||
if (userId is null) return Unauthorized();
|
||||
var result = await _packages.ListAsync(userId, jobId, ct);
|
||||
return result is null ? NotFound() : Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("submitted-packages")]
|
||||
public async Task<ActionResult<SubmittedPackageDto>> CaptureSubmittedPackage(int jobId, CancellationToken ct)
|
||||
{
|
||||
var user = await _users.GetUserAsync(User);
|
||||
if (user is null) return Unauthorized();
|
||||
var result = await _packages.CaptureAsync(user.Id, jobId, Person(user), ct);
|
||||
return result is null ? NotFound() : Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("submitted-packages/{packageId:int}")]
|
||||
public async Task<ActionResult<SubmittedPackageDetailDto>> GetSubmittedPackage(int jobId, int packageId, CancellationToken ct)
|
||||
{
|
||||
var userId = await CurrentUserIdAsync();
|
||||
if (userId is null) return Unauthorized();
|
||||
var result = await _packages.GetAsync(userId, jobId, packageId, ct);
|
||||
return result is null ? NotFound() : Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("submitted-packages/{packageId:int}/attachments/{attachmentId:int}")]
|
||||
public async Task<IActionResult> DownloadSubmittedAttachment(int jobId, int packageId, int attachmentId, CancellationToken ct)
|
||||
{
|
||||
var userId = await CurrentUserIdAsync();
|
||||
if (userId is null) return Unauthorized();
|
||||
var file = await _packages.GetAttachmentAsync(userId, jobId, packageId, attachmentId, ct);
|
||||
return file is null ? NotFound() : PhysicalFile(file.Path, file.ContentType, file.FileName);
|
||||
}
|
||||
|
||||
private async Task<string?> CurrentUserIdAsync() => (await _users.GetUserAsync(User))?.Id;
|
||||
|
||||
private static CvRenderPerson Person(ApplicationUser user)
|
||||
{
|
||||
var name = string.Join(" ", new[] { user.FirstName?.Trim(), user.LastName?.Trim() }.Where(x => !string.IsNullOrWhiteSpace(x)));
|
||||
if (string.IsNullOrWhiteSpace(name)) name = user.DisplayName?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(name)) name = user.UserName?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(name)) name = user.Email?.Trim();
|
||||
return new CvRenderPerson(string.IsNullOrWhiteSpace(name) ? "Your Name" : name, AvatarStorage.Resolve(user.AvatarImageDataUrl));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user