feat/scan (#66)

scan fix

Merge branch 'master' of http://git.kadet.net/system-praktyk/system-praktyk-api into master

Merge branch 'master' of http://git.kadet.net/system-praktyk/system-praktyk-api into master

merge

add document scan endpoint

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-10-18 09:12:13 +02:00
parent 614054acba
commit 6e7bdb72af
3 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,5 @@
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Threading;
using System.Threading.Tasks;
using InternshipSystem.Api.Queries;
@ -61,9 +60,11 @@ namespace InternshipSystem.Api.Controllers
await _context.Entry(edition)
.Collection(e => e.Internships)
.Query()
.Include(i => i.Documentation)
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
internship.AddNewDocument(documentRequest.Description, documentRequest.Type);
await _context.SaveChangesAsync(cancellationToken);
return Ok();
}
@ -86,14 +87,12 @@ namespace InternshipSystem.Api.Controllers
await _context.Entry(edition)
.Collection(e => e.Internships)
.Query()
.Include(i => i.Documentation)
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
var document = await _context.Entry(internship)
.Collection(i => i.Documentation)
.Query()
.FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken);
var document = internship.Documentation.First(d => d.Id == documentId);
document.Scan = memoryStream.ToArray();
document.Scan = new DocumentScan { File = memoryStream.ToArray() };
document.State = DocumentState.Submitted;
await _context.SaveChangesAsync(cancellationToken);
@ -117,9 +116,10 @@ namespace InternshipSystem.Api.Controllers
await _context.Entry(internship)
.Collection(i => i.Documentation)
.Query()
.Include(d => d.Scan)
.FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken);
var stream = new MemoryStream(document.Scan);
var stream = new MemoryStream(document.Scan.File);
return File(stream, "application/pdf");
}

View File

@ -6,9 +6,16 @@ namespace InternshipSystem.Core
{
public long Id { get; set; }
public string Description { get; set; }
public byte[] Scan { get; set; }
public DocumentScan Scan { get; set; }
public DocumentType Type { get; set; }
public DocumentState State { get; set; }
public string RejectionReason { get; set; }
}
public class DocumentScan
{
public long DocumentId { get; set; }
public Document Document { get; set; }
public byte[] File { get; set; }
}
}

View File

@ -45,8 +45,8 @@ namespace InternshipSystem.Core.Entity.Internship
{
var document = Documentation.First(d => d.Id == documentId);
document.Scan = documentScan;
document.State = DocumentState.Submitted;
// document.Scan = documentScan;
// document.State = DocumentState.Submitted;
}
}
}