diff --git a/src/InternshipSystem.Api/ApiProfile.cs b/src/InternshipSystem.Api/ApiProfile.cs index e28ca30..9f20a90 100644 --- a/src/InternshipSystem.Api/ApiProfile.cs +++ b/src/InternshipSystem.Api/ApiProfile.cs @@ -20,6 +20,8 @@ namespace InternshipSystem.Api opt => opt.MapFrom(edition => edition.IsOpen ? "Open" : "Archival")); CreateMap(); + + CreateMap(); CreateMap().IncludeMembers(es => es.Subject); } diff --git a/src/InternshipSystem.Api/Controllers/AccessController.cs b/src/InternshipSystem.Api/Controllers/AccessController.cs index 0109e48..22e10bd 100644 --- a/src/InternshipSystem.Api/Controllers/AccessController.cs +++ b/src/InternshipSystem.Api/Controllers/AccessController.cs @@ -86,7 +86,7 @@ namespace InternshipSystem.Api.Controllers [HttpGet("loginEdition")] [Authorize] - public async Task LoginIntoEdition(Guid editionId, [FromServices] User user, CancellationToken token) + public async Task LoginIntoEdition([FromBody] Guid editionId, [FromServices] User user, CancellationToken token) { var edition = await _context.Editions.FindAsync(editionId); diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 033b2aa..b21af33 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -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); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index d6a2bd1..07ecf55 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -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; } /// @@ -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 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> 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); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index f5de0b1..f01080a 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -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 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); diff --git a/src/InternshipSystem.Api/Services/IInternshipService.cs b/src/InternshipSystem.Api/Services/IInternshipService.cs index 614e053..861703d 100644 --- a/src/InternshipSystem.Api/Services/IInternshipService.cs +++ b/src/InternshipSystem.Api/Services/IInternshipService.cs @@ -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 SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber, + Task SubmitRegistration(RegistrationFormQuery registrationQuery, User user, CancellationToken cancellationToken); - Task AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber, + Task AddDocumentToInternship(DocumentPublishRequest documentRequest, User user, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs index 51eafc5..fc0d9ad 100644 --- a/src/InternshipSystem.Api/Services/InternshipService.cs +++ b/src/InternshipSystem.Api/Services/InternshipService.cs @@ -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 SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber, + public async Task 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 AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber, + public async Task 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(documentRequest); diff --git a/src/InternshipSystem.Core/ValueObject/DocumentState.cs b/src/InternshipSystem.Core/ValueObject/DocumentState.cs index 2a8d863..52efdeb 100644 --- a/src/InternshipSystem.Core/ValueObject/DocumentState.cs +++ b/src/InternshipSystem.Core/ValueObject/DocumentState.cs @@ -2,9 +2,15 @@ { public enum DocumentState { + // Oczekujaca NotSubmitted, + // Oczekuje na akceptacje Submitted, + // Zaakceptowana Accepted, - Rejected + // Odrzucona + Rejected, + // Archiwalna + Archival } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/ValueObject/DocumentType.cs b/src/InternshipSystem.Core/ValueObject/DocumentType.cs index 5acb99a..24f8f10 100644 --- a/src/InternshipSystem.Core/ValueObject/DocumentType.cs +++ b/src/InternshipSystem.Core/ValueObject/DocumentType.cs @@ -2,6 +2,8 @@ { public enum DocumentType { - IPPScan + IppScan, + DeanConsent, + NnwIsurance } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 7126522..64b0621 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -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 { new EditionSubject