From 93bc55a30798caa67e635b92d8d172b6e84a5fb3 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Wed, 26 Aug 2020 19:03:32 +0200 Subject: [PATCH 1/6] InternshipRegistration EndPoint implementation --- src/InternshipSystem.Api/ApiProfile.cs | 3 +- .../Controllers/EditionController.cs | 1 - .../InternshipRegistrationController.cs | 89 ++++++++++++++++++- .../Queries/BranchOfficeForm.cs | 36 ++++++++ .../Queries/CompanyForm.cs | 24 +++++ .../Queries/RegistrationFormQuery.cs | 25 ++++-- .../Entity/BranchOffice.cs | 22 +++++ src/InternshipSystem.Core/Entity/Company.cs | 14 +-- src/InternshipSystem.Core/Entity/Edition.cs | 6 ++ .../Entity/Internship/Internship.cs | 7 +- .../Internship/InternshipRegistration.cs | 10 +++ .../Entity/Internship/InternshipType.cs | 13 ++- src/InternshipSystem.Core/Entity/Report.cs | 6 +- .../DatabaseFiller.cs | 23 +++-- 14 files changed, 241 insertions(+), 38 deletions(-) create mode 100644 src/InternshipSystem.Api/Queries/BranchOfficeForm.cs create mode 100644 src/InternshipSystem.Api/Queries/CompanyForm.cs diff --git a/src/InternshipSystem.Api/ApiProfile.cs b/src/InternshipSystem.Api/ApiProfile.cs index a25d338..2f593e0 100644 --- a/src/InternshipSystem.Api/ApiProfile.cs +++ b/src/InternshipSystem.Api/ApiProfile.cs @@ -1,4 +1,5 @@ -using AutoMapper; +using System; +using AutoMapper; using InternshipSystem.Api.Queries; using InternshipSystem.Core; diff --git a/src/InternshipSystem.Api/Controllers/EditionController.cs b/src/InternshipSystem.Api/Controllers/EditionController.cs index a104275..39e69f7 100644 --- a/src/InternshipSystem.Api/Controllers/EditionController.cs +++ b/src/InternshipSystem.Api/Controllers/EditionController.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using InternshipSystem.Api.Result; -using InternshipSystem.Core; using InternshipSystem.Repository; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index cb48ea4..3747050 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -1,10 +1,14 @@ using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; +using AutoMapper; using InternshipSystem.Api.Queries; +using InternshipSystem.Core; using InternshipSystem.Repository; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; namespace InternshipSystem.Api.Controllers { @@ -12,10 +16,12 @@ namespace InternshipSystem.Api.Controllers public class InternshipRegistrationController : ControllerBase { private InternshipDbContext Context { get; } + private IMapper Mapper { get; } - public InternshipRegistrationController(InternshipDbContext context) + public InternshipRegistrationController(InternshipDbContext context, IMapper mapper) { Context = context; + Mapper = mapper; } /// @@ -29,7 +35,84 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] - public async Task SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, CancellationToken cancellationToken) => - throw new NotImplementedException(); + public async Task SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, + CancellationToken cancellationToken) + { + var validator = new RegistrationFormQuery.Validator(); + var validationResult = await validator.ValidateAsync(registrationQuery, cancellationToken); + + if (!validationResult.IsValid) + { + return BadRequest(validationResult.ToString()); + } + + var internship = await GetCurrentStudentInternship(); + + var internshipRegistration = internship.InternshipRegistration; + + if (registrationQuery.Company != null) + { + var company = registrationQuery.Company.Id.HasValue + ? await Context.Companies.SingleAsync(c => c.Id == registrationQuery.Company.Id, + cancellationToken: cancellationToken) + : Company.CreateCompany(registrationQuery.Company.Nip, registrationQuery.Company.Name); + + internshipRegistration.UpdateCompany(company); + } + + var officeForm = registrationQuery.BranchOffice; + if (officeForm != null) + { + BranchOffice branch; + + if (officeForm.Id.HasValue) + { + branch = await Context.Entry(internshipRegistration.Company) + .Collection(c => c.Branches) + .Query() + .SingleAsync(o => o.Id == officeForm.Id, cancellationToken: cancellationToken); + } + else + { + branch = BranchOffice.CreateBranch(officeForm.Country, officeForm.City, officeForm.PostalCode, + officeForm.Street, officeForm.Building); + internshipRegistration.Company.AddBranchOffice(branch); + } + + internshipRegistration.UpdateBranch(branch); + } + + internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start; + internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End; + + var editionId = Guid.Parse(User.Claims.First(c => c.Type == "Edition").Value); + + var edition = await Context.Editions + .FirstAsync(e => e.Id == editionId, cancellationToken); + + if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) + { + return BadRequest("Edycja nie posiada takiego rodzaju zatrudnienia w dostępnych zatrudnieniach"); + } + + internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; + + await Context.SaveChangesAsync(cancellationToken); + return Ok(); + } + + private async Task GetCurrentStudentInternship() + { + // TODO: rewrite when authentication will be implemented + var edition = await Context + .Editions + .FirstAsync(); + + return await Context.Entry(edition) + .Collection(e => e.Internships) + .Query() + .Include(i => i.InternshipRegistration) + .FirstAsync(); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Queries/BranchOfficeForm.cs b/src/InternshipSystem.Api/Queries/BranchOfficeForm.cs new file mode 100644 index 0000000..5fbbafc --- /dev/null +++ b/src/InternshipSystem.Api/Queries/BranchOfficeForm.cs @@ -0,0 +1,36 @@ +using FluentValidation; + +namespace InternshipSystem.Api.Queries +{ + public class BranchOfficeForm + { + public long? Id { get; set; } + public string Street { get; set; } + public string Building { get; set; } + public string City { get; set; } + public string PostalCode { get; set; } + public string Country { get; set; } + + public class Validator : AbstractValidator + { + public Validator() + { + RuleFor(b => b.Id).NotNull() + .When(c => + !string.IsNullOrEmpty(c.Country) || !string.IsNullOrEmpty(c.City) || + !string.IsNullOrEmpty(c.PostalCode) || !string.IsNullOrEmpty(c.Street) || + !string.IsNullOrEmpty(c.Building)); + RuleFor(b => b.Country).NotNull() + .When(b => !b.Id.HasValue); + RuleFor(b => b.City).NotNull() + .When(b => !b.Id.HasValue); + RuleFor(b => b.PostalCode).NotNull() + .When(b => !b.Id.HasValue); + RuleFor(b => b.Street).NotNull() + .When(b => !b.Id.HasValue); + RuleFor(b => b.Building).NotNull() + .When(b => !b.Id.HasValue); + } + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Queries/CompanyForm.cs b/src/InternshipSystem.Api/Queries/CompanyForm.cs new file mode 100644 index 0000000..330a8f5 --- /dev/null +++ b/src/InternshipSystem.Api/Queries/CompanyForm.cs @@ -0,0 +1,24 @@ +using FluentValidation; + +namespace InternshipSystem.Api.Queries +{ + public class CompanyForm + { + public long? Id { get; set; } + public string Nip { get; set; } + public string Name { get; set; } + + public class Validator : AbstractValidator + { + public Validator() + { + RuleFor(c => c.Id).NotNull() + .When(c => !string.IsNullOrEmpty(c.Nip) || !string.IsNullOrEmpty(c.Name)); + RuleFor(c => c.Nip).NotEmpty() + .When(c => !c.Id.HasValue); + RuleFor(c => c.Name).NotEmpty() + .When(c => !c.Id.HasValue); + } + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs b/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs index fe30ded..77122c9 100644 --- a/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs +++ b/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs @@ -1,15 +1,28 @@ using System; -using InternshipSystem.Core; +using FluentValidation; using InternshipSystem.Core.Entity.Internship; namespace InternshipSystem.Api.Queries { public class RegistrationFormQuery { - public Company Company { get; set; } - public BranchOffice BranchAddress { get; set; } - public DateTime Start { get; set; } - public DateTime End { get; set; } - public InternshipType Type { get; set; } + public CompanyForm Company { get; set; } + public BranchOfficeForm BranchOffice { get; set; } + public DateTime? Start { get; set; } + public DateTime? End { get; set; } + public InternshipType? Type { get; set; } + + public class Validator : AbstractValidator + { + public Validator() + { + RuleFor(rfq => rfq.Company) + .SetValidator(new CompanyForm.Validator()); + RuleFor(rfq => rfq.BranchOffice) + .SetValidator(new BranchOfficeForm.Validator()); + RuleFor(rfq => rfq.BranchOffice).NotNull() + .When(rfq => rfq.Company != null); + } + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/BranchOffice.cs b/src/InternshipSystem.Core/Entity/BranchOffice.cs index 9f3dac9..78e41c8 100644 --- a/src/InternshipSystem.Core/Entity/BranchOffice.cs +++ b/src/InternshipSystem.Core/Entity/BranchOffice.cs @@ -2,8 +2,30 @@ { public class BranchOffice { + public BranchOffice() + { + } + private BranchOffice(BranchAddress address) + { + Address = address; + } + public long Id { get; set; } public BranchAddress Address { get; set; } + + public static BranchOffice CreateBranch(string country, string city, string postalCode, string street, string building) + { + var address = new BranchAddress + { + Building = building, + City = city, + Country = country, + Street = street, + PostalCode = postalCode + }; + + return new BranchOffice(address); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Company.cs b/src/InternshipSystem.Core/Entity/Company.cs index ddbeeb4..67b640d 100644 --- a/src/InternshipSystem.Core/Entity/Company.cs +++ b/src/InternshipSystem.Core/Entity/Company.cs @@ -8,22 +8,22 @@ namespace InternshipSystem.Core public long Id { get; set; } public Nip Nip { get; set; } public string Name { get; set; } - public RangeOfActivity Range { get; set; } public List Branches { get; set; } - public Uri SiteAddress { get; set; } - public Company CreateCompany(string nip, RangeOfActivity range, string name) - { - return new Company + public static Company CreateCompany(string nip, string name) => + new Company { Nip = nip, - Range = range, Name = name }; - } public void AddBranchAddress(BranchAddress branch) { } + + public void AddBranchOffice(BranchOffice createBranch) + { + Branches.Add(createBranch); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Edition.cs b/src/InternshipSystem.Core/Entity/Edition.cs index 165b31c..bd058ed 100644 --- a/src/InternshipSystem.Core/Entity/Edition.cs +++ b/src/InternshipSystem.Core/Entity/Edition.cs @@ -14,6 +14,7 @@ namespace InternshipSystem.Core public Course Course { get; set; } public List Internships { get; set; } public List AvailableSubjects { get; set; } + public List AvailableInternshipTypes { get; set; } public Edition CreateEdition(DateTime start, DateTime end, DateTime reportingStart) { @@ -24,5 +25,10 @@ namespace InternshipSystem.Core ReportingStart = reportingStart }; } + + public bool IsInternshipTypeAllowed(InternshipType registrationQueryType) + { + return AvailableInternshipTypes.Contains(registrationQueryType); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Internship/Internship.cs b/src/InternshipSystem.Core/Entity/Internship/Internship.cs index 52aaf69..666d1e5 100644 --- a/src/InternshipSystem.Core/Entity/Internship/Internship.cs +++ b/src/InternshipSystem.Core/Entity/Internship/Internship.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using InternshipSystem.Core.ValueObject; namespace InternshipSystem.Core { @@ -14,12 +13,14 @@ namespace InternshipSystem.Core public List Approvals { get; set; } public List Documentation { get; set; } + public Edition Edition { get; set; } + public void UpdateDocument(Document document) { var oldDocument = Documentation.First(d => d.Id == document.Id); - oldDocument.Description = document.Description; - oldDocument.Scan = document.Scan; + oldDocument.Description = document.Description ?? oldDocument.Description; + oldDocument.Scan = document.Scan ?? oldDocument.Scan; oldDocument.Type = document.Type; oldDocument.State = DocumentState.Submitted; } diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs index 449230e..e7e8790 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipRegistration.cs @@ -12,5 +12,15 @@ namespace InternshipSystem.Core public DateTime End { get; set; } public InternshipType Type { get; set; } public DocumentState State { get; set; } + + public void UpdateCompany(Company newCompany) + { + Company = newCompany; + } + + public void UpdateBranch(BranchOffice branch) + { + BranchAddress = branch; + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs index d9fb97f..0f554e0 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs @@ -1,9 +1,14 @@ namespace InternshipSystem.Core.Entity.Internship { - public class InternshipType + public enum InternshipType { - public long Id { get; set; } - public string Type { get; set; } - public string Description { get; set; } + FreeInternship, + GraduateInternship, + FreeApprenticeship, + PaidApprenticeship, + ForeignInternship, + UOP, + UD, + UZ } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Report.cs b/src/InternshipSystem.Core/Entity/Report.cs index 944678d..4eeb8e9 100644 --- a/src/InternshipSystem.Core/Entity/Report.cs +++ b/src/InternshipSystem.Core/Entity/Report.cs @@ -1,8 +1,12 @@ -namespace InternshipSystem.Core +using System; + +namespace InternshipSystem.Core { public class Report { public long Id { get; set; } public DocumentState State { get; set; } + public RangeOfActivity Range { get; set; } + public Uri SiteAddress { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index bee6e4b..1b898d1 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -26,9 +26,8 @@ namespace InternshipSystem.Repository { Id = 1, Name = "Intel", - SiteAddress = new Uri("https://www.intel.com/content/www/us/en/jobs/locations/poland.html"), + // SiteAddress = new Uri("https://www.intel.com/content/www/us/en/jobs/locations/poland.html"), Nip = "9570752316", - Range = RangeOfActivity.International, Branches = new List { new BranchOffice @@ -70,9 +69,8 @@ namespace InternshipSystem.Repository { Id = 2, Name = "Asseco Poland", - SiteAddress = new Uri("http://pl.asseco.com"), + // SiteAddress = new Uri("http://pl.asseco.com"), Nip = "5842068320", - Range = RangeOfActivity.National, Branches = new List { new BranchOffice @@ -141,6 +139,13 @@ namespace InternshipSystem.Repository { Name = "Informatyka", }, + AvailableInternshipTypes = new List + { + InternshipType.UOP, + InternshipType.UZ, + InternshipType.UD, + InternshipType.FreeInternship + }, Internships = new List(), } }; @@ -162,10 +167,7 @@ namespace InternshipSystem.Repository InternshipRegistration = new InternshipRegistration { Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel - Type = new InternshipType - { - Type = "UOP" - }, + Type = InternshipType.UOP, Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, @@ -215,10 +217,7 @@ namespace InternshipSystem.Repository InternshipRegistration = new InternshipRegistration { Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco - Type = new InternshipType - { - Type = "UZ" - }, + Type = InternshipType.UZ, Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, From b11211a7562d28e019f9b5845a4c2d5519e5952a Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Fri, 28 Aug 2020 19:01:10 +0200 Subject: [PATCH 2/6] Bad request error message --- .../Controllers/InternshipRegistrationController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 3747050..5914f3e 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -92,7 +92,7 @@ namespace InternshipSystem.Api.Controllers if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) { - return BadRequest("Edycja nie posiada takiego rodzaju zatrudnienia w dostępnych zatrudnieniach"); + return BadRequest("Edition doesn't have this type of employment in available employments type"); } internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; From 5054330f299f61684099e356db46938462d9d812 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Mon, 31 Aug 2020 18:13:30 +0200 Subject: [PATCH 3/6] cleanign --- .../Controllers/AdminController.cs | 2 - .../Controllers/DocumentsController.cs | 10 +- .../Controllers/EditionController.cs | 8 +- .../InternshipRegistrationController.cs | 31 +- .../Controllers/RegistrationController.cs | 12 +- src/InternshipSystem.Api/Security/User.cs | 1 - .../20200828182238_Init.Designer.cs | 609 ------------------ .../Migrations/20200828182238_Init.cs | 438 ------------- .../InternshipDbContextModelSnapshot.cs | 607 ----------------- 9 files changed, 25 insertions(+), 1693 deletions(-) delete mode 100644 src/InternshipSystem.Repository/Migrations/20200828182238_Init.Designer.cs delete mode 100644 src/InternshipSystem.Repository/Migrations/20200828182238_Init.cs delete mode 100644 src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index 3fbb0ef..6a153f8 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -1,7 +1,5 @@ using System.Threading.Tasks; using InternshipSystem.Repository; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; namespace InternshipSystem.Api.Controllers diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 9350e02..3eb8585 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -42,7 +42,7 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [Authorize(Policy = Policies.RegisteredOnly)] - public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest, User user) + public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest) { var validator = new DocumentPublishRequest.Validator(); var validationResult = await validator.ValidateAsync(documentRequest); @@ -52,14 +52,14 @@ namespace InternshipSystem.Api.Controllers return BadRequest(validationResult.ToString()); } - var edition = - await Context.Editions - .FindAsync(user.EditionId.Value); + var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); + + var edition = await Context.Editions.FindAsync(personNumber); var internship = await Context.Entry(edition) .Collection(e => e.Internships) .Query() - .SingleAsync(i => i.Student.Id == user.PersonNumber); + .SingleAsync(i => i.Student.Id == personNumber); var document = Mapper.Map(documentRequest); diff --git a/src/InternshipSystem.Api/Controllers/EditionController.cs b/src/InternshipSystem.Api/Controllers/EditionController.cs index 67c2f81..f9e6774 100644 --- a/src/InternshipSystem.Api/Controllers/EditionController.cs +++ b/src/InternshipSystem.Api/Controllers/EditionController.cs @@ -8,7 +8,6 @@ using AutoMapper.QueryableExtensions; using IdentityServer4.Extensions; using InternshipSystem.Api.Result; using InternshipSystem.Api.Security; -using InternshipSystem.Core.Entity.Internship; using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -41,7 +40,7 @@ namespace InternshipSystem.Api.Controllers [Authorize] public async Task>> GetAvailableEditions(CancellationToken token) { - var personNumber = long.Parse(User.FindFirst("PersonNumber").Value); + var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); var editions = await Context.Editions @@ -69,11 +68,9 @@ namespace InternshipSystem.Api.Controllers [HttpGet("{id}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [Authorize(Policy = "RegisteredForEditionOnly")] + [Authorize(Policy = Policies.RegisteredOnly)] public async Task> GetEditionsConfiguration(Guid id, CancellationToken token) { - var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - var edition = await Context.Editions .Include(e => e.AvailableSubjects) @@ -88,6 +85,5 @@ namespace InternshipSystem.Api.Controllers return Ok(edition); } - } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 5914f3e..2926d6f 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -4,8 +4,10 @@ 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.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -35,6 +37,7 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [Authorize] public async Task SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, CancellationToken cancellationToken) { @@ -46,7 +49,14 @@ namespace InternshipSystem.Api.Controllers return BadRequest(validationResult.ToString()); } - var internship = await GetCurrentStudentInternship(); + var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); + + var edition = await Context.Editions.FindAsync(personNumber); + + var internship = await Context.Entry(edition) + .Collection(e => e.Internships) + .Query() + .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); var internshipRegistration = internship.InternshipRegistration; @@ -85,11 +95,6 @@ namespace InternshipSystem.Api.Controllers internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start; internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End; - var editionId = Guid.Parse(User.Claims.First(c => c.Type == "Edition").Value); - - var edition = await Context.Editions - .FirstAsync(e => e.Id == editionId, cancellationToken); - if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) { return BadRequest("Edition doesn't have this type of employment in available employments type"); @@ -100,19 +105,5 @@ namespace InternshipSystem.Api.Controllers await Context.SaveChangesAsync(cancellationToken); return Ok(); } - - private async Task GetCurrentStudentInternship() - { - // TODO: rewrite when authentication will be implemented - var edition = await Context - .Editions - .FirstAsync(); - - return await Context.Entry(edition) - .Collection(e => e.Internships) - .Query() - .Include(i => i.InternshipRegistration) - .FirstAsync(); - } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index 26931fc..8ecc086 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -35,19 +35,21 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] [Authorize] - public async Task RegisterStudentForEdition([FromBody] Guid registrationCode, User user, CancellationToken token) + public async Task RegisterStudentForEdition([FromBody] Guid registrationCode, CancellationToken token) { - var edition = await _context.Editions.FindAsync(registrationCode); + var edition = await _context.Editions.FindAsync(registrationCode, token); if (edition == null) { return NotFound(); } - - var student = await _context.Students.FindAsync(user.PersonNumber); + + var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); + + var student = await _context.Students.FindAsync(personNumber, token); edition.RegisterInternship(student); - await _context.SaveChangesAsync(); + await _context.SaveChangesAsync(token); return Ok(); } diff --git a/src/InternshipSystem.Api/Security/User.cs b/src/InternshipSystem.Api/Security/User.cs index b569d6f..326547a 100644 --- a/src/InternshipSystem.Api/Security/User.cs +++ b/src/InternshipSystem.Api/Security/User.cs @@ -6,7 +6,6 @@ namespace InternshipSystem.Api.Security { public long PersonNumber { get; set; } public string Name { get; set; } - public Guid? EditionId { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/Migrations/20200828182238_Init.Designer.cs b/src/InternshipSystem.Repository/Migrations/20200828182238_Init.Designer.cs deleted file mode 100644 index 0f84439..0000000 --- a/src/InternshipSystem.Repository/Migrations/20200828182238_Init.Designer.cs +++ /dev/null @@ -1,609 +0,0 @@ -// -using System; -using InternshipSystem.Repository; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace InternshipSystem.Repository.Migrations -{ - [DbContext(typeof(InternshipDbContext))] - [Migration("20200828182238_Init")] - partial class Init - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("InternshipSystem.Core.BranchOffice", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CompanyId") - .HasColumnName("company_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_branch_office"); - - b.HasIndex("CompanyId") - .HasName("ix_branch_office_company_id"); - - b.ToTable("branch_office"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Company", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .HasColumnName("name") - .HasColumnType("text"); - - b.Property("Nip") - .IsRequired() - .HasColumnName("nip") - .HasColumnType("text"); - - b.Property("Range") - .HasColumnName("range") - .HasColumnType("integer"); - - b.Property("SiteAddress") - .HasColumnName("site_address") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_companies"); - - b.ToTable("companies"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Course", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .HasColumnName("name") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_course"); - - b.ToTable("course"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Document", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.Property("InternshipId") - .HasColumnName("internship_id") - .HasColumnType("bigint"); - - b.Property("InternshipId1") - .HasColumnName("internship_id1") - .HasColumnType("bigint"); - - b.Property("RejectionReason") - .HasColumnName("rejection_reason") - .HasColumnType("text"); - - b.Property("Scan") - .HasColumnName("scan") - .HasColumnType("bytea"); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.Property("Type") - .HasColumnName("type") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_document"); - - b.HasIndex("InternshipId") - .HasName("ix_document_internship_id"); - - b.HasIndex("InternshipId1") - .HasName("ix_document_internship_id1"); - - b.ToTable("document"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Edition", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("uuid"); - - b.Property("CourseId") - .HasColumnName("course_id") - .HasColumnType("bigint"); - - b.Property("EditionFinish") - .HasColumnName("edition_finish") - .HasColumnType("timestamp without time zone"); - - b.Property("EditionStart") - .HasColumnName("edition_start") - .HasColumnType("timestamp without time zone"); - - b.Property("ReportingStart") - .HasColumnName("reporting_start") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id") - .HasName("pk_editions"); - - b.HasIndex("CourseId") - .HasName("ix_editions_course_id"); - - b.ToTable("editions"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_internship_subject"); - - b.ToTable("internship_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.Property("Type") - .HasColumnName("type") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_internship_type"); - - b.ToTable("internship_type"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Internship", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("EditionId") - .HasColumnName("edition_id") - .HasColumnType("uuid"); - - b.Property("Grade") - .HasColumnName("grade") - .HasColumnType("real"); - - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - - b.Property("InternshipRegistrationId") - .HasColumnName("internship_registration_id") - .HasColumnType("bigint"); - - b.Property("ReportId") - .HasColumnName("report_id") - .HasColumnType("bigint"); - - b.Property("StudentId") - .HasColumnName("student_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_internship"); - - b.HasIndex("EditionId") - .HasName("ix_internship_edition_id"); - - b.HasIndex("InternshipProgramId") - .HasName("ix_internship_internship_program_id"); - - b.HasIndex("InternshipRegistrationId") - .HasName("ix_internship_internship_registration_id"); - - b.HasIndex("ReportId") - .HasName("ix_internship_report_id"); - - b.HasIndex("StudentId") - .HasName("ix_internship_student_id"); - - b.ToTable("internship"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_internship_program"); - - b.ToTable("internship_program"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("BranchAddressId") - .HasColumnName("branch_address_id") - .HasColumnType("bigint"); - - b.Property("CompanyId") - .HasColumnName("company_id") - .HasColumnType("bigint"); - - b.Property("End") - .HasColumnName("end") - .HasColumnType("timestamp without time zone"); - - b.Property("Start") - .HasColumnName("start") - .HasColumnType("timestamp without time zone"); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.Property("TypeId") - .HasColumnName("type_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_internship_registration"); - - b.HasIndex("BranchAddressId") - .HasName("ix_internship_registration_branch_address_id"); - - b.HasIndex("CompanyId") - .HasName("ix_internship_registration_company_id"); - - b.HasIndex("TypeId") - .HasName("ix_internship_registration_type_id"); - - b.ToTable("internship_registration"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Report", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_report"); - - b.ToTable("report"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Student", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("AlbumNumber") - .HasColumnName("album_number") - .HasColumnType("integer"); - - b.Property("Email") - .HasColumnName("email") - .HasColumnType("text"); - - b.Property("FirstName") - .HasColumnName("first_name") - .HasColumnType("text"); - - b.Property("LastName") - .HasColumnName("last_name") - .HasColumnType("text"); - - b.Property("Semester") - .HasColumnName("semester") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_student"); - - b.ToTable("student"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => - { - b.Property("EditionId") - .HasColumnName("edition_id") - .HasColumnType("uuid"); - - b.Property("InternshipSubjectId") - .HasColumnName("internship_subject_id") - .HasColumnType("bigint"); - - b.HasKey("EditionId", "InternshipSubjectId") - .HasName("pk_edition_subject"); - - b.HasIndex("InternshipSubjectId") - .HasName("ix_edition_subject_internship_subject_id"); - - b.ToTable("edition_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => - { - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - - b.Property("InternshipSubjectId") - .HasColumnName("internship_subject_id") - .HasColumnType("bigint"); - - b.HasKey("InternshipProgramId", "InternshipSubjectId") - .HasName("pk_program_subject"); - - b.HasIndex("InternshipSubjectId") - .HasName("ix_program_subject_internship_subject_id"); - - b.ToTable("program_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.BranchOffice", b => - { - b.HasOne("InternshipSystem.Core.Company", null) - .WithMany("Branches") - .HasForeignKey("CompanyId") - .HasConstraintName("fk_branch_office_companies_company_id"); - - b.OwnsOne("InternshipSystem.Core.BranchAddress", "Address", b1 => - { - b1.Property("BranchOfficeId") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b1.Property("Building") - .HasColumnName("building") - .HasColumnType("text"); - - b1.Property("City") - .HasColumnName("city") - .HasColumnType("text"); - - b1.Property("Country") - .HasColumnName("country") - .HasColumnType("text"); - - b1.Property("PostalCode") - .HasColumnName("postal_code") - .HasColumnType("text"); - - b1.Property("Street") - .HasColumnName("street") - .HasColumnType("text"); - - b1.HasKey("BranchOfficeId") - .HasName("pk_branch_office"); - - b1.ToTable("branch_office"); - - b1.WithOwner() - .HasForeignKey("BranchOfficeId") - .HasConstraintName("fk_branch_address_branch_office_branch_office_id"); - }); - }); - - modelBuilder.Entity("InternshipSystem.Core.Document", b => - { - b.HasOne("InternshipSystem.Core.Internship", null) - .WithMany("Approvals") - .HasForeignKey("InternshipId") - .HasConstraintName("fk_document_internship_internship_id"); - - b.HasOne("InternshipSystem.Core.Internship", null) - .WithMany("Documentation") - .HasForeignKey("InternshipId1") - .HasConstraintName("fk_document_internship_internship_id1"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Edition", b => - { - b.HasOne("InternshipSystem.Core.Course", "Course") - .WithMany() - .HasForeignKey("CourseId") - .HasConstraintName("fk_editions_course_course_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Internship", b => - { - b.HasOne("InternshipSystem.Core.Edition", null) - .WithMany("Internships") - .HasForeignKey("EditionId") - .HasConstraintName("fk_internship_editions_edition_id"); - - b.HasOne("InternshipSystem.Core.InternshipProgram", "InternshipProgram") - .WithMany() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_internship_internship_program_internship_program_id"); - - b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration") - .WithMany() - .HasForeignKey("InternshipRegistrationId") - .HasConstraintName("fk_internship_internship_registration_internship_registration_"); - - b.HasOne("InternshipSystem.Core.Report", "Report") - .WithMany() - .HasForeignKey("ReportId") - .HasConstraintName("fk_internship_report_report_id"); - - b.HasOne("InternshipSystem.Core.Student", "Student") - .WithMany() - .HasForeignKey("StudentId") - .HasConstraintName("fk_internship_student_student_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.OwnsOne("InternshipSystem.Core.Mentor", "Mentor", b1 => - { - b1.Property("InternshipProgramId") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b1.Property("Email") - .HasColumnName("email") - .HasColumnType("text"); - - b1.Property("FirstName") - .HasColumnName("first_name") - .HasColumnType("text"); - - b1.Property("LastName") - .HasColumnName("last_name") - .HasColumnType("text"); - - b1.Property("PhoneNumber") - .IsRequired() - .HasColumnName("mentor_phone_number") - .HasColumnType("text"); - - b1.HasKey("InternshipProgramId") - .HasName("pk_internship_program"); - - b1.ToTable("internship_program"); - - b1.WithOwner() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_mentor_internship_program_internship_program_id"); - }); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") - .WithMany() - .HasForeignKey("BranchAddressId") - .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); - - b.HasOne("InternshipSystem.Core.Company", "Company") - .WithMany() - .HasForeignKey("CompanyId") - .HasConstraintName("fk_internship_registration_companies_company_id"); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") - .WithMany() - .HasForeignKey("TypeId") - .HasConstraintName("fk_internship_registration_internship_type_type_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => - { - b.HasOne("InternshipSystem.Core.Edition", "Edition") - .WithMany("AvailableSubjects") - .HasForeignKey("EditionId") - .HasConstraintName("fk_edition_subject_editions_edition_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipSubject", "Subject") - .WithMany() - .HasForeignKey("InternshipSubjectId") - .HasConstraintName("fk_edition_subject_internship_subject_internship_subject_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => - { - b.HasOne("InternshipSystem.Core.InternshipProgram", "Program") - .WithMany("ChosenSubjects") - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_program_subject_internship_program_internship_program_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipSubject", "Subject") - .WithMany() - .HasForeignKey("InternshipSubjectId") - .HasConstraintName("fk_program_subject_internship_subject_internship_subject_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/InternshipSystem.Repository/Migrations/20200828182238_Init.cs b/src/InternshipSystem.Repository/Migrations/20200828182238_Init.cs deleted file mode 100644 index e1b6129..0000000 --- a/src/InternshipSystem.Repository/Migrations/20200828182238_Init.cs +++ /dev/null @@ -1,438 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace InternshipSystem.Repository.Migrations -{ - public partial class Init : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "companies", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - nip = table.Column(nullable: false), - name = table.Column(nullable: true), - range = table.Column(nullable: false), - site_address = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_companies", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "course", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - name = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_course", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "internship_program", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - first_name = table.Column(nullable: true), - last_name = table.Column(nullable: true), - email = table.Column(nullable: true), - mentor_phone_number = table.Column(nullable: true), - state = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_internship_program", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "internship_subject", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - description = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_internship_subject", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "internship_type", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - type = table.Column(nullable: true), - description = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_internship_type", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "report", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - state = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_report", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "student", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - album_number = table.Column(nullable: false), - first_name = table.Column(nullable: true), - last_name = table.Column(nullable: true), - email = table.Column(nullable: true), - semester = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_student", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "branch_office", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - street = table.Column(nullable: true), - building = table.Column(nullable: true), - city = table.Column(nullable: true), - postal_code = table.Column(nullable: true), - country = table.Column(nullable: true), - company_id = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_branch_office", x => x.id); - table.ForeignKey( - name: "fk_branch_office_companies_company_id", - column: x => x.company_id, - principalTable: "companies", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "editions", - columns: table => new - { - id = table.Column(nullable: false), - edition_start = table.Column(nullable: false), - edition_finish = table.Column(nullable: false), - reporting_start = table.Column(nullable: false), - course_id = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_editions", x => x.id); - table.ForeignKey( - name: "fk_editions_course_course_id", - column: x => x.course_id, - principalTable: "course", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "program_subject", - columns: table => new - { - internship_program_id = table.Column(nullable: false), - internship_subject_id = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_program_subject", x => new { x.internship_program_id, x.internship_subject_id }); - table.ForeignKey( - name: "fk_program_subject_internship_program_internship_program_id", - column: x => x.internship_program_id, - principalTable: "internship_program", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_program_subject_internship_subject_internship_subject_id", - column: x => x.internship_subject_id, - principalTable: "internship_subject", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "internship_registration", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - company_id = table.Column(nullable: true), - branch_address_id = table.Column(nullable: true), - start = table.Column(nullable: false), - end = table.Column(nullable: false), - type_id = table.Column(nullable: true), - state = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_internship_registration", x => x.id); - table.ForeignKey( - name: "fk_internship_registration_branch_office_branch_address_id", - column: x => x.branch_address_id, - principalTable: "branch_office", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_registration_companies_company_id", - column: x => x.company_id, - principalTable: "companies", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_registration_internship_type_type_id", - column: x => x.type_id, - principalTable: "internship_type", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "edition_subject", - columns: table => new - { - edition_id = table.Column(nullable: false), - internship_subject_id = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_edition_subject", x => new { x.edition_id, x.internship_subject_id }); - table.ForeignKey( - name: "fk_edition_subject_editions_edition_id", - column: x => x.edition_id, - principalTable: "editions", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_edition_subject_internship_subject_internship_subject_id", - column: x => x.internship_subject_id, - principalTable: "internship_subject", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "internship", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - student_id = table.Column(nullable: true), - internship_registration_id = table.Column(nullable: true), - internship_program_id = table.Column(nullable: true), - report_id = table.Column(nullable: true), - grade = table.Column(nullable: false), - edition_id = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_internship", x => x.id); - table.ForeignKey( - name: "fk_internship_editions_edition_id", - column: x => x.edition_id, - principalTable: "editions", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_internship_program_internship_program_id", - column: x => x.internship_program_id, - principalTable: "internship_program", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_internship_registration_internship_registration_", - column: x => x.internship_registration_id, - principalTable: "internship_registration", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_report_report_id", - column: x => x.report_id, - principalTable: "report", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_student_student_id", - column: x => x.student_id, - principalTable: "student", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "document", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - description = table.Column(nullable: true), - scan = table.Column(nullable: true), - type = table.Column(nullable: false), - state = table.Column(nullable: false), - rejection_reason = table.Column(nullable: true), - internship_id = table.Column(nullable: true), - internship_id1 = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_document", x => x.id); - table.ForeignKey( - name: "fk_document_internship_internship_id", - column: x => x.internship_id, - principalTable: "internship", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_document_internship_internship_id1", - column: x => x.internship_id1, - principalTable: "internship", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - name: "ix_branch_office_company_id", - table: "branch_office", - column: "company_id"); - - migrationBuilder.CreateIndex( - name: "ix_document_internship_id", - table: "document", - column: "internship_id"); - - migrationBuilder.CreateIndex( - name: "ix_document_internship_id1", - table: "document", - column: "internship_id1"); - - migrationBuilder.CreateIndex( - name: "ix_edition_subject_internship_subject_id", - table: "edition_subject", - column: "internship_subject_id"); - - migrationBuilder.CreateIndex( - name: "ix_editions_course_id", - table: "editions", - column: "course_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_edition_id", - table: "internship", - column: "edition_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_internship_program_id", - table: "internship", - column: "internship_program_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_internship_registration_id", - table: "internship", - column: "internship_registration_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_report_id", - table: "internship", - column: "report_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_student_id", - table: "internship", - column: "student_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_registration_branch_address_id", - table: "internship_registration", - column: "branch_address_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_registration_company_id", - table: "internship_registration", - column: "company_id"); - - migrationBuilder.CreateIndex( - name: "ix_internship_registration_type_id", - table: "internship_registration", - column: "type_id"); - - migrationBuilder.CreateIndex( - name: "ix_program_subject_internship_subject_id", - table: "program_subject", - column: "internship_subject_id"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "document"); - - migrationBuilder.DropTable( - name: "edition_subject"); - - migrationBuilder.DropTable( - name: "program_subject"); - - migrationBuilder.DropTable( - name: "internship"); - - migrationBuilder.DropTable( - name: "internship_subject"); - - migrationBuilder.DropTable( - name: "editions"); - - migrationBuilder.DropTable( - name: "internship_program"); - - migrationBuilder.DropTable( - name: "internship_registration"); - - migrationBuilder.DropTable( - name: "report"); - - migrationBuilder.DropTable( - name: "student"); - - migrationBuilder.DropTable( - name: "course"); - - migrationBuilder.DropTable( - name: "branch_office"); - - migrationBuilder.DropTable( - name: "internship_type"); - - migrationBuilder.DropTable( - name: "companies"); - } - } -} diff --git a/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs deleted file mode 100644 index 59b3a8f..0000000 --- a/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs +++ /dev/null @@ -1,607 +0,0 @@ -// -using System; -using InternshipSystem.Repository; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace InternshipSystem.Repository.Migrations -{ - [DbContext(typeof(InternshipDbContext))] - partial class InternshipDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("InternshipSystem.Core.BranchOffice", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CompanyId") - .HasColumnName("company_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_branch_office"); - - b.HasIndex("CompanyId") - .HasName("ix_branch_office_company_id"); - - b.ToTable("branch_office"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Company", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .HasColumnName("name") - .HasColumnType("text"); - - b.Property("Nip") - .IsRequired() - .HasColumnName("nip") - .HasColumnType("text"); - - b.Property("Range") - .HasColumnName("range") - .HasColumnType("integer"); - - b.Property("SiteAddress") - .HasColumnName("site_address") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_companies"); - - b.ToTable("companies"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Course", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .HasColumnName("name") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_course"); - - b.ToTable("course"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Document", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.Property("InternshipId") - .HasColumnName("internship_id") - .HasColumnType("bigint"); - - b.Property("InternshipId1") - .HasColumnName("internship_id1") - .HasColumnType("bigint"); - - b.Property("RejectionReason") - .HasColumnName("rejection_reason") - .HasColumnType("text"); - - b.Property("Scan") - .HasColumnName("scan") - .HasColumnType("bytea"); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.Property("Type") - .HasColumnName("type") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_document"); - - b.HasIndex("InternshipId") - .HasName("ix_document_internship_id"); - - b.HasIndex("InternshipId1") - .HasName("ix_document_internship_id1"); - - b.ToTable("document"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Edition", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("uuid"); - - b.Property("CourseId") - .HasColumnName("course_id") - .HasColumnType("bigint"); - - b.Property("EditionFinish") - .HasColumnName("edition_finish") - .HasColumnType("timestamp without time zone"); - - b.Property("EditionStart") - .HasColumnName("edition_start") - .HasColumnType("timestamp without time zone"); - - b.Property("ReportingStart") - .HasColumnName("reporting_start") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id") - .HasName("pk_editions"); - - b.HasIndex("CourseId") - .HasName("ix_editions_course_id"); - - b.ToTable("editions"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_internship_subject"); - - b.ToTable("internship_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Description") - .HasColumnName("description") - .HasColumnType("text"); - - b.Property("Type") - .HasColumnName("type") - .HasColumnType("text"); - - b.HasKey("Id") - .HasName("pk_internship_type"); - - b.ToTable("internship_type"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Internship", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("EditionId") - .HasColumnName("edition_id") - .HasColumnType("uuid"); - - b.Property("Grade") - .HasColumnName("grade") - .HasColumnType("real"); - - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - - b.Property("InternshipRegistrationId") - .HasColumnName("internship_registration_id") - .HasColumnType("bigint"); - - b.Property("ReportId") - .HasColumnName("report_id") - .HasColumnType("bigint"); - - b.Property("StudentId") - .HasColumnName("student_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_internship"); - - b.HasIndex("EditionId") - .HasName("ix_internship_edition_id"); - - b.HasIndex("InternshipProgramId") - .HasName("ix_internship_internship_program_id"); - - b.HasIndex("InternshipRegistrationId") - .HasName("ix_internship_internship_registration_id"); - - b.HasIndex("ReportId") - .HasName("ix_internship_report_id"); - - b.HasIndex("StudentId") - .HasName("ix_internship_student_id"); - - b.ToTable("internship"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_internship_program"); - - b.ToTable("internship_program"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("BranchAddressId") - .HasColumnName("branch_address_id") - .HasColumnType("bigint"); - - b.Property("CompanyId") - .HasColumnName("company_id") - .HasColumnType("bigint"); - - b.Property("End") - .HasColumnName("end") - .HasColumnType("timestamp without time zone"); - - b.Property("Start") - .HasColumnName("start") - .HasColumnType("timestamp without time zone"); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.Property("TypeId") - .HasColumnName("type_id") - .HasColumnType("bigint"); - - b.HasKey("Id") - .HasName("pk_internship_registration"); - - b.HasIndex("BranchAddressId") - .HasName("ix_internship_registration_branch_address_id"); - - b.HasIndex("CompanyId") - .HasName("ix_internship_registration_company_id"); - - b.HasIndex("TypeId") - .HasName("ix_internship_registration_type_id"); - - b.ToTable("internship_registration"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Report", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_report"); - - b.ToTable("report"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Student", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("AlbumNumber") - .HasColumnName("album_number") - .HasColumnType("integer"); - - b.Property("Email") - .HasColumnName("email") - .HasColumnType("text"); - - b.Property("FirstName") - .HasColumnName("first_name") - .HasColumnType("text"); - - b.Property("LastName") - .HasColumnName("last_name") - .HasColumnType("text"); - - b.Property("Semester") - .HasColumnName("semester") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_student"); - - b.ToTable("student"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => - { - b.Property("EditionId") - .HasColumnName("edition_id") - .HasColumnType("uuid"); - - b.Property("InternshipSubjectId") - .HasColumnName("internship_subject_id") - .HasColumnType("bigint"); - - b.HasKey("EditionId", "InternshipSubjectId") - .HasName("pk_edition_subject"); - - b.HasIndex("InternshipSubjectId") - .HasName("ix_edition_subject_internship_subject_id"); - - b.ToTable("edition_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => - { - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - - b.Property("InternshipSubjectId") - .HasColumnName("internship_subject_id") - .HasColumnType("bigint"); - - b.HasKey("InternshipProgramId", "InternshipSubjectId") - .HasName("pk_program_subject"); - - b.HasIndex("InternshipSubjectId") - .HasName("ix_program_subject_internship_subject_id"); - - b.ToTable("program_subject"); - }); - - modelBuilder.Entity("InternshipSystem.Core.BranchOffice", b => - { - b.HasOne("InternshipSystem.Core.Company", null) - .WithMany("Branches") - .HasForeignKey("CompanyId") - .HasConstraintName("fk_branch_office_companies_company_id"); - - b.OwnsOne("InternshipSystem.Core.BranchAddress", "Address", b1 => - { - b1.Property("BranchOfficeId") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b1.Property("Building") - .HasColumnName("building") - .HasColumnType("text"); - - b1.Property("City") - .HasColumnName("city") - .HasColumnType("text"); - - b1.Property("Country") - .HasColumnName("country") - .HasColumnType("text"); - - b1.Property("PostalCode") - .HasColumnName("postal_code") - .HasColumnType("text"); - - b1.Property("Street") - .HasColumnName("street") - .HasColumnType("text"); - - b1.HasKey("BranchOfficeId") - .HasName("pk_branch_office"); - - b1.ToTable("branch_office"); - - b1.WithOwner() - .HasForeignKey("BranchOfficeId") - .HasConstraintName("fk_branch_address_branch_office_branch_office_id"); - }); - }); - - modelBuilder.Entity("InternshipSystem.Core.Document", b => - { - b.HasOne("InternshipSystem.Core.Internship", null) - .WithMany("Approvals") - .HasForeignKey("InternshipId") - .HasConstraintName("fk_document_internship_internship_id"); - - b.HasOne("InternshipSystem.Core.Internship", null) - .WithMany("Documentation") - .HasForeignKey("InternshipId1") - .HasConstraintName("fk_document_internship_internship_id1"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Edition", b => - { - b.HasOne("InternshipSystem.Core.Course", "Course") - .WithMany() - .HasForeignKey("CourseId") - .HasConstraintName("fk_editions_course_course_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.Internship", b => - { - b.HasOne("InternshipSystem.Core.Edition", null) - .WithMany("Internships") - .HasForeignKey("EditionId") - .HasConstraintName("fk_internship_editions_edition_id"); - - b.HasOne("InternshipSystem.Core.InternshipProgram", "InternshipProgram") - .WithMany() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_internship_internship_program_internship_program_id"); - - b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration") - .WithMany() - .HasForeignKey("InternshipRegistrationId") - .HasConstraintName("fk_internship_internship_registration_internship_registration_"); - - b.HasOne("InternshipSystem.Core.Report", "Report") - .WithMany() - .HasForeignKey("ReportId") - .HasConstraintName("fk_internship_report_report_id"); - - b.HasOne("InternshipSystem.Core.Student", "Student") - .WithMany() - .HasForeignKey("StudentId") - .HasConstraintName("fk_internship_student_student_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.OwnsOne("InternshipSystem.Core.Mentor", "Mentor", b1 => - { - b1.Property("InternshipProgramId") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b1.Property("Email") - .HasColumnName("email") - .HasColumnType("text"); - - b1.Property("FirstName") - .HasColumnName("first_name") - .HasColumnType("text"); - - b1.Property("LastName") - .HasColumnName("last_name") - .HasColumnType("text"); - - b1.Property("PhoneNumber") - .IsRequired() - .HasColumnName("mentor_phone_number") - .HasColumnType("text"); - - b1.HasKey("InternshipProgramId") - .HasName("pk_internship_program"); - - b1.ToTable("internship_program"); - - b1.WithOwner() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_mentor_internship_program_internship_program_id"); - }); - }); - - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") - .WithMany() - .HasForeignKey("BranchAddressId") - .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); - - b.HasOne("InternshipSystem.Core.Company", "Company") - .WithMany() - .HasForeignKey("CompanyId") - .HasConstraintName("fk_internship_registration_companies_company_id"); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") - .WithMany() - .HasForeignKey("TypeId") - .HasConstraintName("fk_internship_registration_internship_type_type_id"); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => - { - b.HasOne("InternshipSystem.Core.Edition", "Edition") - .WithMany("AvailableSubjects") - .HasForeignKey("EditionId") - .HasConstraintName("fk_edition_subject_editions_edition_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipSubject", "Subject") - .WithMany() - .HasForeignKey("InternshipSubjectId") - .HasConstraintName("fk_edition_subject_internship_subject_internship_subject_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => - { - b.HasOne("InternshipSystem.Core.InternshipProgram", "Program") - .WithMany("ChosenSubjects") - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_program_subject_internship_program_internship_program_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipSubject", "Subject") - .WithMany() - .HasForeignKey("InternshipSubjectId") - .HasConstraintName("fk_program_subject_internship_subject_internship_subject_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} From 203a6a597d3a3a024def8a33cfd70595988c71ed Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Mon, 31 Aug 2020 18:21:16 +0200 Subject: [PATCH 4/6] cancellationToken --- .../Controllers/DocumentsController.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 3eb8585..dc9a22a 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using InternshipSystem.Api.Queries; @@ -42,10 +43,10 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [Authorize(Policy = Policies.RegisteredOnly)] - public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest) + public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest, CancellationToken cancellationToken) { var validator = new DocumentPublishRequest.Validator(); - var validationResult = await validator.ValidateAsync(documentRequest); + var validationResult = await validator.ValidateAsync(documentRequest, cancellationToken); if (!validationResult.IsValid) { @@ -59,7 +60,7 @@ namespace InternshipSystem.Api.Controllers var internship = await Context.Entry(edition) .Collection(e => e.Internships) .Query() - .SingleAsync(i => i.Student.Id == personNumber); + .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); var document = Mapper.Map(documentRequest); From c401081dc8f9698a138629082e0ad1ecf410dd74 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Fri, 4 Sep 2020 21:30:40 +0200 Subject: [PATCH 5/6] add IntetnshipService --- .../Controllers/DocumentsController.cs | 46 +------ .../InternshipRegistrationController.cs | 71 +---------- .../Controllers/RegistrationController.cs | 2 - .../Services/IInternshipService.cs | 16 +++ .../Services/InternshipService.cs | 114 ++++++++++++++++++ src/InternshipSystem.Api/Startup.cs | 3 + 6 files changed, 145 insertions(+), 107 deletions(-) create mode 100644 src/InternshipSystem.Api/Services/IInternshipService.cs create mode 100644 src/InternshipSystem.Api/Services/InternshipService.cs diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index dc9a22a..3406f9b 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -1,17 +1,11 @@ -using System; -using System.Diagnostics; -using System.Linq; -using System.Threading; +using System.Threading; using System.Threading.Tasks; -using AutoMapper; using InternshipSystem.Api.Queries; using InternshipSystem.Api.Security; -using InternshipSystem.Core; -using InternshipSystem.Repository; +using InternshipSystem.Api.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; namespace InternshipSystem.Api.Controllers { @@ -19,13 +13,11 @@ namespace InternshipSystem.Api.Controllers [Route("document")] public class DocumentsController : ControllerBase { - private InternshipDbContext Context { get; } - private IMapper Mapper { get; } + private readonly IInternshipService _internshipService; - public DocumentsController(InternshipDbContext context, IMapper mapper) + public DocumentsController(IInternshipService internshipService) { - Context = context; - Mapper = mapper; + _internshipService = internshipService; } /// @@ -54,34 +46,8 @@ namespace InternshipSystem.Api.Controllers } var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - - var edition = await Context.Editions.FindAsync(personNumber); - var internship = await Context.Entry(edition) - .Collection(e => e.Internships) - .Query() - .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); - - var document = Mapper.Map(documentRequest); - - if (documentRequest.Id.HasValue) - { - try - { - internship.UpdateDocument(document); - } - catch (InvalidOperationException) - { - return NotFound(); - } - } - else - { - internship.AddNewDocument(document); - } - - await Context.SaveChangesAsync(); - return Ok(); + return await _internshipService.AddDocumentToInternship(documentRequest, personNumber, cancellationToken); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 2926d6f..44c8eb6 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -1,29 +1,22 @@ -using System; -using System.Linq; -using System.Threading; +using System.Threading; using System.Threading.Tasks; -using AutoMapper; using InternshipSystem.Api.Queries; using InternshipSystem.Api.Security; -using InternshipSystem.Core; -using InternshipSystem.Repository; +using InternshipSystem.Api.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; namespace InternshipSystem.Api.Controllers { [Route("internshipRegistration")] public class InternshipRegistrationController : ControllerBase { - private InternshipDbContext Context { get; } - private IMapper Mapper { get; } + private readonly IInternshipService _internshipService; - public InternshipRegistrationController(InternshipDbContext context, IMapper mapper) + public InternshipRegistrationController(IInternshipService internshipService) { - Context = context; - Mapper = mapper; + _internshipService = internshipService; } /// @@ -50,60 +43,8 @@ namespace InternshipSystem.Api.Controllers } var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - - var edition = await Context.Editions.FindAsync(personNumber); - var internship = await Context.Entry(edition) - .Collection(e => e.Internships) - .Query() - .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); - - var internshipRegistration = internship.InternshipRegistration; - - if (registrationQuery.Company != null) - { - var company = registrationQuery.Company.Id.HasValue - ? await Context.Companies.SingleAsync(c => c.Id == registrationQuery.Company.Id, - cancellationToken: cancellationToken) - : Company.CreateCompany(registrationQuery.Company.Nip, registrationQuery.Company.Name); - - internshipRegistration.UpdateCompany(company); - } - - var officeForm = registrationQuery.BranchOffice; - if (officeForm != null) - { - BranchOffice branch; - - if (officeForm.Id.HasValue) - { - branch = await Context.Entry(internshipRegistration.Company) - .Collection(c => c.Branches) - .Query() - .SingleAsync(o => o.Id == officeForm.Id, cancellationToken: cancellationToken); - } - else - { - branch = BranchOffice.CreateBranch(officeForm.Country, officeForm.City, officeForm.PostalCode, - officeForm.Street, officeForm.Building); - internshipRegistration.Company.AddBranchOffice(branch); - } - - internshipRegistration.UpdateBranch(branch); - } - - internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start; - internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End; - - if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) - { - return BadRequest("Edition doesn't have this type of employment in available employments type"); - } - - internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; - - await Context.SaveChangesAsync(cancellationToken); - return Ok(); + return await _internshipService.SubmitRegistration(registrationQuery, personNumber, cancellationToken); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index 8ecc086..89d2cb2 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -1,9 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using InternshipSystem.Api.Result; using InternshipSystem.Api.Security; -using InternshipSystem.Core; using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/src/InternshipSystem.Api/Services/IInternshipService.cs b/src/InternshipSystem.Api/Services/IInternshipService.cs new file mode 100644 index 0000000..614e053 --- /dev/null +++ b/src/InternshipSystem.Api/Services/IInternshipService.cs @@ -0,0 +1,16 @@ +using System.Threading; +using System.Threading.Tasks; +using InternshipSystem.Api.Queries; +using Microsoft.AspNetCore.Mvc; + +namespace InternshipSystem.Api.Services +{ + public interface IInternshipService + { + Task SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber, + CancellationToken cancellationToken); + + Task AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber, + CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs new file mode 100644 index 0000000..4bcaa03 --- /dev/null +++ b/src/InternshipSystem.Api/Services/InternshipService.cs @@ -0,0 +1,114 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using AutoMapper; +using InternshipSystem.Api.Queries; +using InternshipSystem.Core; +using InternshipSystem.Repository; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace InternshipSystem.Api.Services +{ + public class InternshipService : IInternshipService + { + private readonly InternshipDbContext _context; + private IMapper Mapper { get; } + + public InternshipService(InternshipDbContext context, IMapper mapper) + { + _context = context; + Mapper = mapper; + } + + public async Task SubmitRegistration(RegistrationFormQuery registrationQuery, long personNumber, + CancellationToken cancellationToken) + { + var edition = await _context.Editions.FindAsync(personNumber); + + var internship = await _context.Entry(edition) + .Collection(e => e.Internships) + .Query() + .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); + + var internshipRegistration = internship.InternshipRegistration; + + if (registrationQuery.Company != null) + { + var company = registrationQuery.Company.Id.HasValue + ? await _context.Companies.SingleAsync(c => c.Id == registrationQuery.Company.Id, + cancellationToken: cancellationToken) + : Company.CreateCompany(registrationQuery.Company.Nip, registrationQuery.Company.Name); + + internshipRegistration.UpdateCompany(company); + } + + var officeForm = registrationQuery.BranchOffice; + if (officeForm != null) + { + BranchOffice branch; + + if (officeForm.Id.HasValue) + { + branch = await _context.Entry(internshipRegistration.Company) + .Collection(c => c.Branches) + .Query() + .SingleAsync(o => o.Id == officeForm.Id, cancellationToken: cancellationToken); + } + else + { + branch = BranchOffice.CreateBranch(officeForm.Country, officeForm.City, officeForm.PostalCode, + officeForm.Street, officeForm.Building); + internshipRegistration.Company.AddBranchOffice(branch); + } + + internshipRegistration.UpdateBranch(branch); + } + + internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start; + internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End; + + if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) + { + return new BadRequestObjectResult("Edition doesn't have this type of employment in available employments type"); + } + + internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; + + await _context.SaveChangesAsync(cancellationToken); + return new OkResult(); + } + + public async Task AddDocumentToInternship(DocumentPublishRequest documentRequest, long personNumber, + CancellationToken cancellationToken) + { + var edition = await _context.Editions.FindAsync(personNumber); + + var internship = await _context.Entry(edition) + .Collection(e => e.Internships) + .Query() + .SingleAsync(i => i.Student.Id == personNumber, cancellationToken); + + var document = Mapper.Map(documentRequest); + + if (documentRequest.Id.HasValue) + { + try + { + internship.UpdateDocument(document); + } + catch (InvalidOperationException) + { + return new NotFoundResult(); + } + } + else + { + internship.AddNewDocument(document); + } + + await _context.SaveChangesAsync(cancellationToken); + return new OkResult(); + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index af8297f..ab34720 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -6,6 +6,8 @@ using InternshipSystem.Api.Extensions; using InternshipSystem.Api.ModelBinders; using InternshipSystem.Api.Options; using InternshipSystem.Api.Security; +using InternshipSystem.Api.Services; +using InternshipSystem.Core; using InternshipSystem.Repository; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -36,6 +38,7 @@ namespace InternshipSystem.Api options.IncludeXmlComments(xmlPath); }) .AddScoped() + .AddScoped() .AddScoped() .AddAutoMapper(cfg => cfg.AddProfile()) .AddStudentAuthentication() From cb2afcb89703e26219304b6673d89b3076964e22 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 5 Sep 2020 20:50:22 +0200 Subject: [PATCH 6/6] Resolve InternshipType List in Edition problem --- .../Controllers/CompaniesController.cs | 2 +- src/InternshipSystem.Core/Entity/Edition.cs | 5 +++-- .../Entity/Internship/InternshipType.cs | 16 ++++++++-------- .../UglyOrmArtifacts/EditionInternshipType.cs | 11 +++++++++++ .../DatabaseFiller.cs | 10 +++++----- 5 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs diff --git a/src/InternshipSystem.Api/Controllers/CompaniesController.cs b/src/InternshipSystem.Api/Controllers/CompaniesController.cs index 430e81d..b23aaef 100644 --- a/src/InternshipSystem.Api/Controllers/CompaniesController.cs +++ b/src/InternshipSystem.Api/Controllers/CompaniesController.cs @@ -38,7 +38,7 @@ namespace InternshipSystem.Api.Controllers .ToListAsync(cancellationToken); /// - /// Get companies matching provided paginated query + /// Get company branches matching provided paginated query /// /// Paginated query description /// diff --git a/src/InternshipSystem.Core/Entity/Edition.cs b/src/InternshipSystem.Core/Entity/Edition.cs index 53f64ad..d6ee476 100644 --- a/src/InternshipSystem.Core/Entity/Edition.cs +++ b/src/InternshipSystem.Core/Entity/Edition.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using InternshipSystem.Core.Entity.Internship; using InternshipSystem.Core.UglyOrmArtifacts; @@ -14,7 +15,7 @@ namespace InternshipSystem.Core public Course Course { get; set; } public List Internships { get; set; } public List AvailableSubjects { get; set; } - public List AvailableInternshipTypes { get; set; } + public List AvailableInternshipTypes { get; set; } public bool IsOpen => EditionFinish < DateTime.Today; @@ -30,7 +31,7 @@ namespace InternshipSystem.Core public bool IsInternshipTypeAllowed(InternshipType registrationQueryType) { - return AvailableInternshipTypes.Contains(registrationQueryType); + return AvailableInternshipTypes.Select(it => it.InternshipType).Contains(registrationQueryType); } public void RegisterInternship(Student student) diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs index 0f554e0..e810e05 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs @@ -2,13 +2,13 @@ { public enum InternshipType { - FreeInternship, - GraduateInternship, - FreeApprenticeship, - PaidApprenticeship, - ForeignInternship, - UOP, - UD, - UZ + FreeInternship = 0, + GraduateInternship = 1, + FreeApprenticeship = 2, + PaidApprenticeship = 3, + ForeignInternship = 4, + UOP = 5, + UD = 6, + UZ = 7, } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs b/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs new file mode 100644 index 0000000..f8c03c2 --- /dev/null +++ b/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs @@ -0,0 +1,11 @@ +using System; +using InternshipSystem.Core.Entity.Internship; + +namespace InternshipSystem.Core.UglyOrmArtifacts +{ + public class EditionInternshipType + { + public long Id { get; set; } + public InternshipType InternshipType { get; set; } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 1b898d1..c3f135a 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -139,12 +139,12 @@ namespace InternshipSystem.Repository { Name = "Informatyka", }, - AvailableInternshipTypes = new List + AvailableInternshipTypes = new List { - InternshipType.UOP, - InternshipType.UZ, - InternshipType.UD, - InternshipType.FreeInternship + new EditionInternshipType() { InternshipType = InternshipType.UOP }, + new EditionInternshipType() { InternshipType = InternshipType.UZ }, + new EditionInternshipType() { InternshipType = InternshipType.UD }, + new EditionInternshipType() { InternshipType = InternshipType.FreeInternship }, }, Internships = new List(), }