diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 92c5a8b..f680c0f 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -116,7 +116,7 @@ namespace InternshipSystem.Api.Controllers return Ok(); } - [HttpGet("{documentId}/scan")] + [HttpGet("{documentId}/scan/download")] [Authorize(Policy = Policies.RegisteredOnly)] public async Task GetDocumentScan(long documentId, [FromQuery] string disposition, [FromServices] User user, CancellationToken cancellationToken) { @@ -146,5 +146,33 @@ namespace InternshipSystem.Api.Controllers return File(stream, document.Scan.Mime); } + + [HttpGet("{documentId}/scan")] + [Authorize(Policy = Policies.RegisteredOnly)] + public async Task GetDocumentScanData(long documentId, [FromServices] User user, CancellationToken cancellationToken) + { + var edition = await _context.Editions.FirstAsync(e => e.Id == user.EditionId, cancellationToken); + + var internship = + await _context.Entry(edition) + .Collection(e => e.Internships) + .Query() + .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); + + var scan = + await _context.Entry(internship) + .Collection(i => i.Documentation) + .Query() + .Include(d => d.Scan) + .Select(s => new {s.Id, s.Scan.Filename, s.Scan.Mime, s.Scan.Size}) + .FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken); + + if (scan == null) + { + return NotFound(); + } + + return Ok(scan); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index a808437..d3a1b97 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -38,6 +38,7 @@ namespace InternshipSystem.Api.Controllers { var edition = await _context.Editions .Include(e => e.Internships) + .ThenInclude(i => i.Student) .FirstOrDefaultAsync(e => e.Id.Equals(registrationCode), cancellationToken: token); if (edition == null)