Add approvals Merge branch 'master' of http://git.kadet.net/system-praktyk/system-praktyk-api into 5fb44c0b2c2818016e8c23d3 XD Co-authored-by: Michal Bohdanowicz <m.w.bohdanowicz@gmail.com>
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using InternshipSystem.Api.Security;
|
|
using InternshipSystem.Core.ValueObject;
|
|
using InternshipSystem.Repository;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace InternshipSystem.Api.Controllers
|
|
{
|
|
[Route("internship/report")]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
private readonly InternshipDbContext _context;
|
|
|
|
public ReportController(InternshipDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
|
public async Task<ActionResult> PostReport([FromBody] JObject reportValue, [FromServices] User user, CancellationToken ct)
|
|
{
|
|
var edition = await _context.Editions
|
|
.FindAsync(user.EditionId);
|
|
|
|
var internship = await _context.Entry(edition)
|
|
.Collection(e => e.Internships)
|
|
.Query()
|
|
.Include(i => i.Report)
|
|
.Include(i => i.Documentation)
|
|
.SingleAsync(i => i.Student.Id == user.PersonNumber, ct);
|
|
|
|
internship.Report.UpdateReport(reportValue.ToString(Formatting.None));
|
|
internship.AddNewDocument("", DocumentType.InternshipEvaluation);
|
|
|
|
await _context.SaveChangesAsync(ct);
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
|
public async Task<ActionResult> GetReport([FromServices] User user, CancellationToken ct)
|
|
{
|
|
var edition = await _context.Editions
|
|
.FindAsync(user.EditionId);
|
|
|
|
var internship = await _context.Entry(edition)
|
|
.Collection(e => e.Internships)
|
|
.Query()
|
|
.Include(i => i.Report)
|
|
.SingleAsync(i => i.Student.Id == user.PersonNumber, ct);
|
|
|
|
return Ok(JsonConvert.DeserializeObject(internship.Report.Value));
|
|
}
|
|
}
|
|
} |