feat/report (#91)

fix

fix

Co-authored-by: Michal Bohdanowicz <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2021-01-10 21:12:32 +01:00
parent 2e1903429b
commit b68a8480bd
4 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,59 @@
using System.Threading;
using System.Threading.Tasks;
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 long? Id { get; set; }
public string Label { get; set; }
public string LabelEng { get; set; }
public string Description { get; set; }

View File

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

View File

@ -347,6 +347,7 @@ namespace InternshipSystem.Repository
}
}
},
Report = Report.Create()
},
new Internship
{