fix everything (#72)

fix everything

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-11-06 20:54:48 +01:00
parent 80dda549bf
commit 3b60331091
2 changed files with 30 additions and 1 deletions

View File

@ -116,7 +116,7 @@ namespace InternshipSystem.Api.Controllers
return Ok();
}
[HttpGet("{documentId}/scan")]
[HttpGet("{documentId}/scan/download")]
[Authorize(Policy = Policies.RegisteredOnly)]
public async Task<ActionResult> 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<ActionResult> 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);
}
}
}

View File

@ -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)