From 0d6213496318b6aeb1a7e94aedf2b1cf3308eb54 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sun, 27 Sep 2020 11:25:03 +0200 Subject: [PATCH 1/5] Fixes + GetCurrentEditionInternship --- src/InternshipSystem.Api/ApiProfile.cs | 2 + .../Controllers/AccessController.cs | 2 +- .../Controllers/DocumentsController.cs | 2 +- .../InternshipRegistrationController.cs | 42 ++++++++++++++++--- .../Controllers/RegistrationController.cs | 9 +++- .../Services/IInternshipService.cs | 5 ++- .../Services/InternshipService.cs | 13 +++--- .../ValueObject/DocumentState.cs | 8 +++- .../ValueObject/DocumentType.cs | 4 +- .../DatabaseFiller.cs | 6 +-- 10 files changed, 71 insertions(+), 22 deletions(-) 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 From 058d6d30bf9c30f3788b7744bb545a9c1e27b0a5 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sun, 27 Sep 2020 12:03:13 +0200 Subject: [PATCH 2/5] SubmitRegistrationForm - fixes --- .../Controllers/InternshipRegistrationController.cs | 6 +----- src/InternshipSystem.Api/Services/InternshipService.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 07ecf55..0f35ff5 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -1,15 +1,11 @@ -using System.Linq; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Queries; using InternshipSystem.Api.Security; -using InternshipSystem.Core.Commands; 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; using Microsoft.EntityFrameworkCore; diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs index fc0d9ad..fa920d0 100644 --- a/src/InternshipSystem.Api/Services/InternshipService.cs +++ b/src/InternshipSystem.Api/Services/InternshipService.cs @@ -25,11 +25,16 @@ namespace InternshipSystem.Api.Services public async Task SubmitRegistration(RegistrationFormQuery registrationQuery, User user, CancellationToken cancellationToken) { - var edition = await _context.Editions.FindAsync(user.EditionId); + var edition = await _context.Editions + .Include(e => e.AvailableInternshipTypes) + .FirstOrDefaultAsync(e => e.Id.Equals(user.EditionId), cancellationToken: cancellationToken); var internship = await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.InternshipRegistration) + .Include(i => i.InternshipRegistration.Company) + .Include(i => i.InternshipRegistration.BranchAddress) .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); var internshipRegistration = internship.InternshipRegistration; @@ -74,7 +79,7 @@ namespace InternshipSystem.Api.Services return new BadRequestObjectResult("Edition doesn't have this type of employment in available employments type"); } - internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; + internshipRegistration.Type = registrationQuery.Type != null ? edition.AvailableInternshipTypes.Find(ai => ai.Id.Equals(registrationQuery.Type.Id)) : internshipRegistration.Type; await _context.SaveChangesAsync(cancellationToken); return new OkResult(); @@ -88,6 +93,7 @@ namespace InternshipSystem.Api.Services var internship = await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.Documentation) .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); var document = Mapper.Map(documentRequest); From a06811fc9f31e81bc86100b1448b786d19cc75c1 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sun, 27 Sep 2020 12:23:50 +0200 Subject: [PATCH 3/5] get edition info by guid fix + add course info --- src/InternshipSystem.Api/Controllers/EditionController.cs | 3 ++- src/InternshipSystem.Api/Result/EditionConfigurationResult.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/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; } From 2576fda4c8c52f7b9f1d36e5103cfa9191c05c2c Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sun, 27 Sep 2020 14:17:47 +0200 Subject: [PATCH 4/5] One context again --- .../Controllers/CompaniesController.cs | 26 +++++++++---------- .../Controllers/RegistrationController.cs | 7 ++--- .../ApplicationBuilderExtensions.cs | 4 +-- src/InternshipSystem.Api/Startup.cs | 2 -- .../DatabaseFiller.cs | 10 +++++++ .../InternshipPractiseSupervisorDbContext.cs | 12 --------- ...nshipPractiseSupervisorDbContextFactory.cs | 16 ------------ ...ner.cs => 20200927114840_init.Designer.cs} | 4 +-- ...3103350_init.cs => 20200927114840_init.cs} | 0 ...cs => InternshipDbContextModelSnapshot.cs} | 4 +-- 10 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs delete mode 100644 src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs rename src/InternshipSystem.Repository/Migrations/{20200923103350_init.Designer.cs => 20200927114840_init.Designer.cs} (99%) rename src/InternshipSystem.Repository/Migrations/{20200923103350_init.cs => 20200927114840_init.cs} (100%) rename src/InternshipSystem.Repository/Migrations/{InternshipPractiseSupervisorDbContextModelSnapshot.cs => InternshipDbContextModelSnapshot.cs} (99%) 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/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index f01080a..19a92c6 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -1,9 +1,7 @@ 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; @@ -22,7 +20,7 @@ namespace InternshipSystem.Api.Controllers { _context = context; } - + /// /// Register student for edition using provided registration code /// @@ -51,9 +49,8 @@ namespace InternshipSystem.Api.Controllers 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/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.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 64b0621..be55afa 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -169,6 +169,16 @@ namespace InternshipSystem.Repository public async Task FillEditions() { + var student = new Student + { + FirstName = "Trzeci", + LastName = "Trzecikowski", + AlbumNumber = 142351, + Email = "s102137@student.pg.edu.pl", + }; + + await Context.Students.AddAsync(student); + var editions = new List { new Edition 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) { From 74e0665aed882ed37a4b053a1d41d9c1740b492d Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sun, 27 Sep 2020 14:39:40 +0200 Subject: [PATCH 5/5] Revert --- src/InternshipSystem.Repository/DatabaseFiller.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index be55afa..64b0621 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -169,16 +169,6 @@ namespace InternshipSystem.Repository public async Task FillEditions() { - var student = new Student - { - FirstName = "Trzeci", - LastName = "Trzecikowski", - AlbumNumber = 142351, - Email = "s102137@student.pg.edu.pl", - }; - - await Context.Students.AddAsync(student); - var editions = new List { new Edition