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/CompaniesController.cs b/src/InternshipSystem.Api/Controllers/CompaniesController.cs index 59b99ad..9502fac 100644 --- a/src/InternshipSystem.Api/Controllers/CompaniesController.cs +++ b/src/InternshipSystem.Api/Controllers/CompaniesController.cs @@ -18,14 +18,12 @@ namespace InternshipSystem.Api.Controllers [Route("companies")] public class CompaniesController : ControllerBase { - public CompaniesController(InternshipDbContext context, InternshipPractiseSupervisorDbContext practiseSupervisorDbContext) + public CompaniesController(InternshipDbContext context) { Context = context; - PractiseSupervisorDbContext = practiseSupervisorDbContext; } private InternshipDbContext Context { get; } - private InternshipPractiseSupervisorDbContext PractiseSupervisorDbContext { get; } /// /// Get companies matching provided paginated query @@ -94,7 +92,7 @@ namespace InternshipSystem.Api.Controllers if (companyForm.Id.HasValue) { - var companyToUpdate = await PractiseSupervisorDbContext.Companies.FindAsync(companyForm.Id); + var companyToUpdate = await Context.Companies.FindAsync(companyForm.Id); if (companyToUpdate != null) { @@ -113,10 +111,10 @@ namespace InternshipSystem.Api.Controllers Name = companyForm.Name, Nip = companyForm.Nip, }; - await PractiseSupervisorDbContext.Companies.AddAsync(newCompany, cancellationToken); + await Context.Companies.AddAsync(newCompany, cancellationToken); } - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Company updated successfully"); } @@ -135,7 +133,7 @@ namespace InternshipSystem.Api.Controllers [Authorize] public async Task DeleteCompany(long companyId, CancellationToken cancellationToken) { - var companyToDelete = await PractiseSupervisorDbContext.Companies + var companyToDelete = await Context.Companies .Include(c => c.Branches) .FirstOrDefaultAsync(c => c.Id.Equals(companyId), cancellationToken: cancellationToken); @@ -144,9 +142,9 @@ namespace InternshipSystem.Api.Controllers return NotFound($"Company with id: {companyId} does not exist"); } - PractiseSupervisorDbContext.Companies.Attach(companyToDelete); - PractiseSupervisorDbContext.Companies.Remove(companyToDelete); - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + Context.Companies.Attach(companyToDelete); + Context.Companies.Remove(companyToDelete); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Company with id: {companyId} deleted successfully"); } @@ -174,7 +172,7 @@ namespace InternshipSystem.Api.Controllers return BadRequest(validationResult.ToString()); } - var company = await PractiseSupervisorDbContext.Companies + var company = await Context.Companies .Include(c => c.Branches) .FirstOrDefaultAsync(c => c.Id.Equals(companyId), cancellationToken: cancellationToken); @@ -214,7 +212,7 @@ namespace InternshipSystem.Api.Controllers company.Branches.Add(newBranchOffice); } - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Branch office updated successfully"); } @@ -234,7 +232,7 @@ namespace InternshipSystem.Api.Controllers public async Task DeleteBranch(long branchOfficeId, CancellationToken cancellationToken) { var company = - await PractiseSupervisorDbContext.Companies + await Context.Companies .Include(c => c.Branches) .Where(c => c.Branches.Any(b => b.Id.Equals(branchOfficeId))) .FirstOrDefaultAsync(cancellationToken: cancellationToken); @@ -247,7 +245,7 @@ namespace InternshipSystem.Api.Controllers var branchOffice = company.Branches.Find(b => b.Id.Equals(branchOfficeId)); company.Branches.Remove(branchOffice); - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Branch office with id: {branchOfficeId} deleted successfully"); } } 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/EditionController.cs b/src/InternshipSystem.Api/Controllers/EditionController.cs index 777524c..49e7c08 100644 --- a/src/InternshipSystem.Api/Controllers/EditionController.cs +++ b/src/InternshipSystem.Api/Controllers/EditionController.cs @@ -66,12 +66,13 @@ namespace InternshipSystem.Api.Controllers [HttpGet("{id}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [Authorize(Policy = Policies.RegisteredOnly)] + [Authorize] public async Task> GetEditionsConfiguration(Guid id, CancellationToken token) { var edition = await Context.Editions .Include(e => e.AvailableSubjects) + .Include(e => e.Course) .Where(e => e.Id.Equals(id)) .ProjectTo(Mapper.ConfigurationProvider) .FirstOrDefaultAsync(token); diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index bcaf82f..0fd4a25 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -6,6 +6,9 @@ using InternshipSystem.Api.Security; using InternshipSystem.Api.UseCases; using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; +using InternshipSystem.Api.Services; +using InternshipSystem.Core; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -15,11 +18,11 @@ namespace InternshipSystem.Api.Controllers [Route("internshipRegistration")] public class InternshipRegistrationController : ControllerBase { - private readonly InternshipDbContext _dbContext; + private readonly InternshipDbContext _context; public InternshipRegistrationController(InternshipDbContext dbContext) { - _dbContext = dbContext; + _context = dbContext; } /// @@ -38,10 +41,10 @@ namespace InternshipSystem.Api.Controllers [FromServices] User user, CancellationToken cancellationToken) { - var edition = await _dbContext.Editions.FirstAsync(e => e.Id == user.EditionId, cancellationToken); + var edition = await _context.Editions.FirstAsync(e => e.Id == user.EditionId, cancellationToken); var internshipRegistration = - await _dbContext + await _context .Entry(edition) .Collection(e => e.Internships) .Query() @@ -52,13 +55,41 @@ namespace InternshipSystem.Api.Controllers .ThenInclude(c => c.Branches) .FirstAsync(cancellationToken); - var useCase = new UpdateInternshipRegistrationUseCase(_dbContext, internshipRegistration, edition, user); + var useCase = new UpdateInternshipRegistrationUseCase(_context, internshipRegistration, edition, user); var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken); - await _dbContext.SaveChangesAsync(cancellationToken); + await _context.SaveChangesAsync(cancellationToken); return Ok(result); } + + [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..19a92c6 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -6,6 +6,7 @@ using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; namespace InternshipSystem.Api.Controllers { @@ -19,7 +20,7 @@ namespace InternshipSystem.Api.Controllers { _context = context; } - + /// /// Register student for edition using provided registration code /// @@ -35,20 +36,21 @@ 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); - + return Ok(); } - } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs index 5dffba4..b82f2b3 100644 --- a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs +++ b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs @@ -17,7 +17,7 @@ namespace InternshipSystem.Api.Extensions try { using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetService(); context.Database.Migrate(); @@ -35,7 +35,7 @@ namespace InternshipSystem.Api.Extensions public static IApplicationBuilder UseDefaultData(this IApplicationBuilder app, bool useDefaultData) { using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetService(); var filler = serviceScope.ServiceProvider.GetService(); context.Database.Migrate(); diff --git a/src/InternshipSystem.Api/Result/EditionConfigurationResult.cs b/src/InternshipSystem.Api/Result/EditionConfigurationResult.cs index 5ded37a..7472297 100644 --- a/src/InternshipSystem.Api/Result/EditionConfigurationResult.cs +++ b/src/InternshipSystem.Api/Result/EditionConfigurationResult.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using InternshipSystem.Core; using InternshipSystem.Core.Entity.Internship; using InternshipSystem.Core.UglyOrmArtifacts; @@ -8,6 +9,7 @@ namespace InternshipSystem.Api.Result public class EditionConfigurationResult { public List AvailableSubjects { get; set; } + public Course Course { get; set; } public DateTime EditionStart { get; set; } public DateTime EditionFinish { get; set; } public DateTime ReportingStart { get; set; } diff --git a/src/InternshipSystem.Api/Services/IInternshipService.cs b/src/InternshipSystem.Api/Services/IInternshipService.cs index 12c86bc..042eef0 100644 --- a/src/InternshipSystem.Api/Services/IInternshipService.cs +++ b/src/InternshipSystem.Api/Services/IInternshipService.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Queries; +using InternshipSystem.Api.Security; using Microsoft.AspNetCore.Mvc; namespace InternshipSystem.Api.Services diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs index 1cda9f0..b7766cd 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; @@ -22,15 +23,16 @@ namespace InternshipSystem.Api.Services } - 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); + .Include(i => i.Documentation) + .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); var document = Mapper.Map(documentRequest); diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index e2db791..3dfb538 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -42,8 +42,6 @@ namespace InternshipSystem.Api services .AddDbContext(o => o.UseNpgsql(Configuration.GetConnectionString("InternshipDatabase"))) - .AddDbContext(o => - o.UseNpgsql(Configuration.GetConnectionString("InternshipDatabase"))) .AddScoped() .AddScoped() .AddScoped() diff --git a/src/InternshipSystem.Core/ValueObject/DocumentState.cs b/src/InternshipSystem.Core/ValueObject/DocumentState.cs index 465aa58..4776b16 100644 --- a/src/InternshipSystem.Core/ValueObject/DocumentState.cs +++ b/src/InternshipSystem.Core/ValueObject/DocumentState.cs @@ -2,9 +2,15 @@ { public enum DocumentState { + // Oczekujaca Draft, + // 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 diff --git a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs b/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs deleted file mode 100644 index d7e66bb..0000000 --- a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -using InternshipSystem.Core; -using Microsoft.EntityFrameworkCore; - -namespace InternshipSystem.Repository -{ - public class InternshipPractiseSupervisorDbContext : InternshipDbContext - { - public InternshipPractiseSupervisorDbContext(DbContextOptions options) : base(options) - { - } - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs b/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs deleted file mode 100644 index 57b3a2b..0000000 --- a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; - -namespace InternshipSystem.Repository -{ - public class InternshipPractiseSupervisorDbContextFactory : IDesignTimeDbContextFactory - { - public InternshipPractiseSupervisorDbContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu"); - - return new InternshipPractiseSupervisorDbContext(optionsBuilder.Options); - } - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs b/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs similarity index 99% rename from src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs rename to src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs index fddfc9e..79cf8f6 100644 --- a/src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs +++ b/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs @@ -9,8 +9,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { - [DbContext(typeof(InternshipPractiseSupervisorDbContext))] - [Migration("20200923103350_init")] + [DbContext(typeof(InternshipDbContext))] + [Migration("20200927114840_init")] partial class init { protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/src/InternshipSystem.Repository/Migrations/20200923103350_init.cs b/src/InternshipSystem.Repository/Migrations/20200927114840_init.cs similarity index 100% rename from src/InternshipSystem.Repository/Migrations/20200923103350_init.cs rename to src/InternshipSystem.Repository/Migrations/20200927114840_init.cs diff --git a/src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs similarity index 99% rename from src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs rename to src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs index c99d560..529a966 100644 --- a/src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs +++ b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs @@ -8,8 +8,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { - [DbContext(typeof(InternshipPractiseSupervisorDbContext))] - partial class InternshipPractiseSupervisorDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(InternshipDbContext))] + partial class InternshipDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) {