feat/report #91

Merged
maxchil merged 2 commits from feat/report into master 2021-01-10 21:12:55 +01:00
3 changed files with 61 additions and 2 deletions
Showing only changes of commit 82378e1fd6 - Show all commits

View File

@ -1,7 +1,59 @@
namespace InternshipSystem.Api.Controllers using System.Threading;
{ using System.Threading.Tasks;
public class ReportController using InternshipSystem.Api.Security;
{ 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)
.SingleAsync(i => i.Student.Id == user.PersonNumber, ct);
internship.Report.UpdateReport(reportValue.ToString(Formatting.None));
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));
}
} }
} }

View File

@ -79,6 +79,7 @@ namespace InternshipSystem.Api.Controllers
public class FieldCreateRequest public class FieldCreateRequest
{ {
public long? Id { get; set; }
public string Label { get; set; } public string Label { get; set; }
public string LabelEng { get; set; } public string LabelEng { get; set; }
public string Description { get; set; } public string Description { get; set; }

View File

@ -12,5 +12,11 @@ namespace InternshipSystem.Core
{ {
return new Report(); return new Report();
} }
public void UpdateReport(string reportValue)
{
Value = reportValue;
State = DocumentState.Submitted;
}
} }
} }