Merge pull request 'Fixes + GetCurrentEditionInternship' (#48) from MoreEndpoints into master
This commit is contained in:
commit
12a1081c8d
@ -20,6 +20,8 @@ namespace InternshipSystem.Api
|
||||
opt => opt.MapFrom(edition => edition.IsOpen ? "Open" : "Archival"));
|
||||
|
||||
CreateMap<Edition, EditionConfigurationResult>();
|
||||
|
||||
CreateMap<InternshipSubject, InternshipSubject>();
|
||||
|
||||
CreateMap<EditionSubject, InternshipSubject>().IncludeMembers(es => es.Subject);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
|
||||
[HttpGet("loginEdition")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> LoginIntoEdition(Guid editionId, [FromServices] User user, CancellationToken token)
|
||||
public async Task<ActionResult> LoginIntoEdition([FromBody] Guid editionId, [FromServices] User user, CancellationToken token)
|
||||
{
|
||||
var edition = await _context.Editions.FindAsync(editionId);
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
return BadRequest(validationResult.ToString());
|
||||
}
|
||||
|
||||
return await _internshipService.AddDocumentToInternship(documentRequest, user.PersonNumber, cancellationToken);
|
||||
return await _internshipService.AddDocumentToInternship(documentRequest, user, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InternshipSystem.Api.Queries;
|
||||
using InternshipSystem.Api.Security;
|
||||
@ -7,6 +8,7 @@ using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using InternshipSystem.Api.Security;
|
||||
using InternshipSystem.Api.Services;
|
||||
using InternshipSystem.Core;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -18,10 +20,12 @@ namespace InternshipSystem.Api.Controllers
|
||||
public class InternshipRegistrationController : ControllerBase
|
||||
{
|
||||
private readonly IInternshipService _internshipService;
|
||||
|
||||
public InternshipRegistrationController(IInternshipService internshipService)
|
||||
private readonly InternshipDbContext _context;
|
||||
|
||||
public InternshipRegistrationController(IInternshipService internshipService, InternshipDbContext context)
|
||||
{
|
||||
_internshipService = internshipService;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -35,7 +39,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[Authorize]
|
||||
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||
public async Task<ActionResult> SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery,
|
||||
[FromServices] User user, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -47,7 +51,35 @@ namespace InternshipSystem.Api.Controllers
|
||||
return BadRequest(validationResult.ToString());
|
||||
}
|
||||
|
||||
return await _internshipService.SubmitRegistration(registrationQuery, user.PersonNumber, cancellationToken);
|
||||
return await _internshipService.SubmitRegistration(registrationQuery, user, cancellationToken);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||
public async Task<ActionResult<Internship>> GetCurrentEditionInternship([FromServices] User user, CancellationToken cancellationToken)
|
||||
{
|
||||
var edition = await _context.Editions
|
||||
.FindAsync(user.EditionId);
|
||||
|
||||
var internship = await _context.Entry(edition)
|
||||
.Collection(e => e.Internships)
|
||||
.Query()
|
||||
.Include(i => i.Student)
|
||||
.Include(i => i.InternshipRegistration)
|
||||
.Include(i => i.InternshipRegistration.Company)
|
||||
.Include(i => i.InternshipRegistration.BranchAddress)
|
||||
.Include(i => i.InternshipRegistration.Type)
|
||||
.Include(i => i.InternshipProgram)
|
||||
.Include(i => i.Report)
|
||||
.Include(i => i.Approvals)
|
||||
.Include(i => i.Documentation)
|
||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||
|
||||
internship.Edition = null;
|
||||
return Ok(internship);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InternshipSystem.Api.Security;
|
||||
using InternshipSystem.Core;
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InternshipSystem.Api.Controllers
|
||||
{
|
||||
@ -35,14 +38,16 @@ namespace InternshipSystem.Api.Controllers
|
||||
[Authorize]
|
||||
public async Task<IActionResult> RegisterStudentForEdition([FromBody] Guid registrationCode, [FromServices] User user, CancellationToken token)
|
||||
{
|
||||
var edition = await _context.Editions.FindAsync(registrationCode, token);
|
||||
var edition = await _context.Editions
|
||||
.Include(e => e.Internships)
|
||||
.FirstOrDefaultAsync(e => e.Id.Equals(registrationCode), cancellationToken: token);
|
||||
|
||||
if (edition == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var student = await _context.Students.FindAsync(user.PersonNumber, token);
|
||||
var student = await _context.Students.FindAsync(user.PersonNumber);
|
||||
|
||||
edition.RegisterInternship(student);
|
||||
await _context.SaveChangesAsync(token);
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InternshipSystem.Api.Queries;
|
||||
using InternshipSystem.Api.Security;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace InternshipSystem.Api.Services
|
||||
{
|
||||
public interface IInternshipService
|
||||
{
|
||||
Task<ActionResult> SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber,
|
||||
Task<ActionResult> SubmitRegistration(RegistrationFormQuery registrationQuery, User user,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
Task<ActionResult> AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber,
|
||||
Task<ActionResult> AddDocumentToInternship(DocumentPublishRequest documentRequest, User user,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using InternshipSystem.Api.Queries;
|
||||
using InternshipSystem.Api.Security;
|
||||
using InternshipSystem.Core;
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -21,15 +22,15 @@ namespace InternshipSystem.Api.Services
|
||||
Mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<ActionResult> SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber,
|
||||
public async Task<ActionResult> SubmitRegistration(RegistrationFormQuery registrationQuery, User user,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var edition = await _context.Editions.FindAsync(personNumber);
|
||||
var edition = await _context.Editions.FindAsync(user.EditionId);
|
||||
|
||||
var internship = await _context.Entry(edition)
|
||||
.Collection(e => e.Internships)
|
||||
.Query()
|
||||
.SingleAsync(i => i.Student.Id == personNumber, cancellationToken);
|
||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||
|
||||
var internshipRegistration = internship.InternshipRegistration;
|
||||
|
||||
@ -79,15 +80,15 @@ namespace InternshipSystem.Api.Services
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
public async Task<ActionResult> AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber,
|
||||
public async Task<ActionResult> AddDocumentToInternship(DocumentPublishRequest documentRequest, User user,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var edition = await _context.Editions.FindAsync(personNumber);
|
||||
var edition = await _context.Editions.FindAsync(user.EditionId);
|
||||
|
||||
var internship = await _context.Entry(edition)
|
||||
.Collection(e => e.Internships)
|
||||
.Query()
|
||||
.SingleAsync(i => i.Student.Id == personNumber, cancellationToken);
|
||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||
|
||||
var document = Mapper.Map<Document>(documentRequest);
|
||||
|
||||
|
@ -2,9 +2,15 @@
|
||||
{
|
||||
public enum DocumentState
|
||||
{
|
||||
// Oczekujaca
|
||||
NotSubmitted,
|
||||
// Oczekuje na akceptacje
|
||||
Submitted,
|
||||
// Zaakceptowana
|
||||
Accepted,
|
||||
Rejected
|
||||
// Odrzucona
|
||||
Rejected,
|
||||
// Archiwalna
|
||||
Archival
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
{
|
||||
public enum DocumentType
|
||||
{
|
||||
IPPScan
|
||||
IppScan,
|
||||
DeanConsent,
|
||||
NnwIsurance
|
||||
}
|
||||
}
|
@ -174,9 +174,9 @@ namespace InternshipSystem.Repository
|
||||
new Edition
|
||||
{
|
||||
Id = Guid.Parse("138da8a3-855c-4b17-9bd2-5f357679efa9"),
|
||||
EditionStart = new DateTime(2000, 5, 10),
|
||||
EditionFinish = new DateTime(2000, 11, 10),
|
||||
ReportingStart = new DateTime(2000, 9, 30),
|
||||
EditionStart = new DateTime(2020, 5, 10),
|
||||
EditionFinish = new DateTime(2020, 12, 10),
|
||||
ReportingStart = new DateTime(2020, 9, 30),
|
||||
AvailableSubjects = new List<EditionSubject>
|
||||
{
|
||||
new EditionSubject
|
||||
|
Loading…
Reference in New Issue
Block a user