feat/report (#91)
fix fix Co-authored-by: Michal Bohdanowicz <m.w.bohdanowicz@gmail.com>
This commit is contained in:
parent
2e1903429b
commit
b68a8480bd
src
InternshipSystem.Api/Controllers
InternshipSystem.Core/Entity
InternshipSystem.Repository
59
src/InternshipSystem.Api/Controllers/ReportController.cs
Normal file
59
src/InternshipSystem.Api/Controllers/ReportController.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
@ -12,5 +12,11 @@ namespace InternshipSystem.Core
|
|||||||
{
|
{
|
||||||
return new Report();
|
return new Report();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateReport(string reportValue)
|
||||||
|
{
|
||||||
|
Value = reportValue;
|
||||||
|
State = DocumentState.Submitted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -347,6 +347,7 @@ namespace InternshipSystem.Repository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Report = Report.Create()
|
||||||
},
|
},
|
||||||
new Internship
|
new Internship
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user