From a508f9f4a88c4a9cd32562350cb75fa1117c82fa Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 12 Sep 2020 14:17:57 +0200 Subject: [PATCH 1/5] static pages --- .../Controllers/AdminController.cs | 14 ++++- .../Controllers/StaticPagesController.cs | 56 +++++++++++++++++++ .../Entity/StaticPage.cs | 10 ++++ .../DatabaseFiller.cs | 26 +++++++++ .../InternshipDbContext.cs | 2 +- 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 src/InternshipSystem.Api/Controllers/StaticPagesController.cs create mode 100644 src/InternshipSystem.Core/Entity/StaticPage.cs diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index 6a153f8..ce73595 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -17,9 +17,11 @@ namespace InternshipSystem.Api.Controllers [HttpPost("fill")] - public async Task Fill() { + public async Task Fill() + { await FillerService.FillCompanies(); await FillerService.FillEditions(); + await FillerService.FillStaticPages(); return Ok(); } @@ -31,9 +33,17 @@ namespace InternshipSystem.Api.Controllers } [HttpPost("fill/editions")] - public async Task FillEditionsAsync() { + public async Task FillEditionsAsync() + { await FillerService.FillEditions(); return Ok(); } + + [HttpPost("fill/staticPages")] + public async Task FillStaticPagesAsync() + { + await FillerService.FillStaticPages(); + return Ok(); + } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/StaticPagesController.cs b/src/InternshipSystem.Api/Controllers/StaticPagesController.cs new file mode 100644 index 0000000..e819202 --- /dev/null +++ b/src/InternshipSystem.Api/Controllers/StaticPagesController.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using InternshipSystem.Core; +using InternshipSystem.Repository; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace InternshipSystem.Api.Controllers +{ + [ApiController] + [Route("staticPage")] + public class StaticPagesController : ControllerBase + { + public StaticPagesController(InternshipDbContext context) + { + Context = context; + } + private InternshipDbContext Context { get; } + + /// + /// Get all static pages + /// + /// List of static pages with titles and content + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> GetStaticPages(CancellationToken cancellationToken) => + await Context.StaticPages + .ToListAsync(cancellationToken); + + /// + /// Get static page + /// + /// Name of page + /// Static page title and content + [HttpGet("{accessName}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task> GetStaticPage(string accessName, CancellationToken cancellationToken) + { + var page = + await Context.StaticPages + .Where(p => p.AccessName.Trim().ToLower().Equals(accessName.Trim().ToLower())) + .FirstOrDefaultAsync(cancellationToken); + + if (page == null) + { + return NotFound(); + } + + return Ok(page); + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/StaticPage.cs b/src/InternshipSystem.Core/Entity/StaticPage.cs new file mode 100644 index 0000000..9cb91e9 --- /dev/null +++ b/src/InternshipSystem.Core/Entity/StaticPage.cs @@ -0,0 +1,10 @@ +namespace InternshipSystem.Core +{ + public class StaticPage + { + public long? Id { get; set; } + public string AccessName { get; set; } + public string Title { get; set; } + public string Content { get; set; } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index c3f135a..2d35976 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -253,6 +253,32 @@ namespace InternshipSystem.Repository await Context.SaveChangesAsync(); } + public async Task FillStaticPages() + { + var staticPages = new List + { + new StaticPage + { + AccessName = "regulations", + Title = "Regulamin Praktyk", + Content = + "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quare ad ea primum, si videtur; Duo Reges: constructio interrete. Eam tum adesse, cum dolor omnis absit; Sed ad bona praeterita redeamus. Facillimum id quidem est, inquam. Apud ceteros autem philosophos, qui quaesivit aliquid, tacet;

" + + "

Quorum altera prosunt, nocent altera. Eam stabilem appellas. Sed nimis multa. Quo plebiscito decreta a senatu est consuli quaestio Cn. Sin laboramus, quis est, qui alienae modum statuat industriae? Quod quidem nobis non saepe contingit. Si autem id non concedatur, non continuo vita beata tollitur. " + + "Illum mallem levares, quo optimum atque humanissimum virum, Cn. Id est enim, de quo quaerimus.

Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Sin dicit obscurari quaedam nec apparere, quia valde parva sint, nos quoque concedimus; Et quod est munus, quod opus sapientiae? Ab hoc autem quaedam non melius quam veteres, quaedam omnino relicta.

" + + "Prosto spod bazy ;D" + }, + new StaticPage + { + AccessName = "info", + Title = "Informacje", + Content = + "

Nowe zmiany:

" + } + }; + await Context.StaticPages.AddRangeAsync(staticPages); + await Context.SaveChangesAsync(); + } + // new InternshipType // { // Type = "FreeInternship", diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs index cd73ffb..f95f1f5 100644 --- a/src/InternshipSystem.Repository/InternshipDbContext.cs +++ b/src/InternshipSystem.Repository/InternshipDbContext.cs @@ -9,7 +9,7 @@ namespace InternshipSystem.Repository { public DbSet Companies { get; set; } public DbSet Editions { get; set; } - + public DbSet StaticPages { get; set; } public DbSet Students { get; set; } public InternshipDbContext(DbContextOptions options) From a06991a318b20ff0a8d6cd4d804a0838d766ffb8 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 12 Sep 2020 16:03:05 +0200 Subject: [PATCH 2/5] Rewrite InternshipType --- .../Controllers/AdminController.cs | 8 ++ .../Controllers/InternshipTypesController.cs | 61 ++++++++++ .../Queries/RegistrationFormQuery.cs | 2 +- .../Services/InternshipService.cs | 2 +- src/InternshipSystem.Core/Entity/Edition.cs | 4 +- .../Entity/Internship/InternshipType.cs | 15 +-- .../Entity/StaticPage.cs | 2 +- .../UglyOrmArtifacts/EditionInternshipType.cs | 11 -- .../DatabaseFiller.cs | 113 ++++++++++-------- .../InternshipDbContext.cs | 1 + 10 files changed, 141 insertions(+), 78 deletions(-) create mode 100644 src/InternshipSystem.Api/Controllers/InternshipTypesController.cs delete mode 100644 src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index ce73595..0c943a5 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -20,6 +20,7 @@ namespace InternshipSystem.Api.Controllers public async Task Fill() { await FillerService.FillCompanies(); + await FillerService.FillInternshipTypes(); await FillerService.FillEditions(); await FillerService.FillStaticPages(); return Ok(); @@ -31,6 +32,13 @@ namespace InternshipSystem.Api.Controllers await FillerService.FillCompanies(); return Ok(); } + + [HttpPost("fill/internshipTypes")] + public async Task FillInternshipTypesAsync() + { + await FillerService.FillInternshipTypes(); + return Ok(); + } [HttpPost("fill/editions")] public async Task FillEditionsAsync() diff --git a/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs new file mode 100644 index 0000000..d4afa36 --- /dev/null +++ b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using InternshipSystem.Api.Security; +using InternshipSystem.Core.Entity.Internship; +using InternshipSystem.Repository; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace InternshipSystem.Api.Controllers +{ + [ApiController] + [Route("internshipType")] + public class InternshipTypesController : ControllerBase + { + + public InternshipTypesController(InternshipDbContext context) + { + Context = context; + } + private InternshipDbContext Context { get; } + + /// + /// Get all internship types + /// + /// List of internship types + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> GetAllInternshipTypes(CancellationToken cancellationToken) => + await Context.InternshipTypes + .ToListAsync(cancellationToken); + + /// + /// Get static page + /// + /// List of internship types for edition + [HttpGet("forCurrentEdition")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [Authorize] + public async Task>> GetInternshipTypesForEdition([FromServices] User user, CancellationToken cancellationToken) + { + var edition = + await Context.Editions + .Include(e => e.AvailableInternshipTypes) + .Where(e => e.Id.Equals(user.EditionId)) + .FirstOrDefaultAsync(cancellationToken: cancellationToken); + + if (edition == null) + { + return NotFound(); + } + + return Ok(edition.AvailableInternshipTypes); + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs b/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs index 77122c9..c1aad76 100644 --- a/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs +++ b/src/InternshipSystem.Api/Queries/RegistrationFormQuery.cs @@ -10,7 +10,7 @@ namespace InternshipSystem.Api.Queries public BranchOfficeForm BranchOffice { get; set; } public DateTime? Start { get; set; } public DateTime? End { get; set; } - public InternshipType? Type { get; set; } + public InternshipType Type { get; set; } public class Validator : AbstractValidator { diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs index 4bcaa03..51eafc5 100644 --- a/src/InternshipSystem.Api/Services/InternshipService.cs +++ b/src/InternshipSystem.Api/Services/InternshipService.cs @@ -68,7 +68,7 @@ namespace InternshipSystem.Api.Services internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start; internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End; - if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value)) + if (registrationQuery.Type != null && edition.IsInternshipTypeAllowed(registrationQuery.Type)) { return new BadRequestObjectResult("Edition doesn't have this type of employment in available employments type"); } diff --git a/src/InternshipSystem.Core/Entity/Edition.cs b/src/InternshipSystem.Core/Entity/Edition.cs index d6ee476..16fd29c 100644 --- a/src/InternshipSystem.Core/Entity/Edition.cs +++ b/src/InternshipSystem.Core/Entity/Edition.cs @@ -15,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; @@ -31,7 +31,7 @@ namespace InternshipSystem.Core public bool IsInternshipTypeAllowed(InternshipType registrationQueryType) { - return AvailableInternshipTypes.Select(it => it.InternshipType).Contains(registrationQueryType); + return AvailableInternshipTypes.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 e810e05..5065f12 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs @@ -1,14 +1,9 @@ namespace InternshipSystem.Core.Entity.Internship { - public enum InternshipType - { - FreeInternship = 0, - GraduateInternship = 1, - FreeApprenticeship = 2, - PaidApprenticeship = 3, - ForeignInternship = 4, - UOP = 5, - UD = 6, - UZ = 7, + public class InternshipType + { + public long Id { get; set; } + public string Type { get; set; } + public string Description { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/StaticPage.cs b/src/InternshipSystem.Core/Entity/StaticPage.cs index 9cb91e9..b4329bd 100644 --- a/src/InternshipSystem.Core/Entity/StaticPage.cs +++ b/src/InternshipSystem.Core/Entity/StaticPage.cs @@ -2,7 +2,7 @@ { public class StaticPage { - public long? Id { get; set; } + public long Id { get; set; } public string AccessName { get; set; } public string Title { get; set; } public string Content { get; set; } diff --git a/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs b/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs deleted file mode 100644 index f8c03c2..0000000 --- a/src/InternshipSystem.Core/UglyOrmArtifacts/EditionInternshipType.cs +++ /dev/null @@ -1,11 +0,0 @@ -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 2d35976..bbb1693 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -102,12 +102,62 @@ namespace InternshipSystem.Repository await Context.SaveChangesAsync(); } + public async Task FillInternshipTypes() + { + var internshipTypes = new List + { + new InternshipType + { + Type = "FreeInternship", + Description = "Praktyka bezpłatna", + }, + new InternshipType + { + Type = "GraduateInternship", + Description = "Praktyka absolwencka", + }, + new InternshipType + { + Type = "FreeApprenticeship", + Description = "Praktyka bezpłatna", + }, + new InternshipType + { + Type = "PaidApprenticeship", + Description = "np. przemysłowy", + }, + new InternshipType + { + Type = "ForeignInternship", + Description = "np. IAESTE, ERASMUS", + }, + new InternshipType + { + Type = "UOP", + Description = "umowa o pracę", + }, + new InternshipType + { + Type = "UD", + Description = "umowa o dzieło", + }, + new InternshipType + { + Type = "UZ", + Description = "umowa zlecenie", + }, + }; + await Context.InternshipTypes.AddRangeAsync(internshipTypes); + await Context.SaveChangesAsync(); + } + public async Task FillEditions() { var editions = new List { 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), @@ -139,12 +189,12 @@ namespace InternshipSystem.Repository { Name = "Informatyka", }, - AvailableInternshipTypes = new List + AvailableInternshipTypes = new List { - new EditionInternshipType() { InternshipType = InternshipType.UOP }, - new EditionInternshipType() { InternshipType = InternshipType.UZ }, - new EditionInternshipType() { InternshipType = InternshipType.UD }, - new EditionInternshipType() { InternshipType = InternshipType.FreeInternship }, + Context.InternshipTypes.First(t => t.Type.Equals("UOP")), + Context.InternshipTypes.First(t => t.Type.Equals("UZ")), + Context.InternshipTypes.First(t => t.Type.Equals("UD")), + Context.InternshipTypes.First(t => t.Type.Equals("FreeInternship")), }, Internships = new List(), } @@ -166,15 +216,15 @@ namespace InternshipSystem.Repository }, InternshipRegistration = new InternshipRegistration { - Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel - Type = InternshipType.UOP, + Company = Context.Companies.First(c => c.Name.Equals("Intel")), + Type = Context.InternshipTypes.First(t => t.Type.Equals("UOP")), Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, BranchAddress = Context.Companies .Include(c => c.Branches) - .First(c => c.Id.Equals(1)) + .First(c => c.Name.Equals("Intel")) .Branches .First(), }, @@ -216,15 +266,15 @@ namespace InternshipSystem.Repository }, InternshipRegistration = new InternshipRegistration { - Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco - Type = InternshipType.UZ, + Company = Context.Companies.First(c => c.Name.Equals("Asseco Poland")), + Type = Context.InternshipTypes.First(t => t.Type.Equals("UZ")), Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, BranchAddress = Context.Companies .Include(c => c.Branches) - .First(c => c.Id.Equals(2)) + .First(c => c.Name.Equals("Asseco Poland")) .Branches .First(), }, @@ -278,46 +328,5 @@ namespace InternshipSystem.Repository await Context.StaticPages.AddRangeAsync(staticPages); await Context.SaveChangesAsync(); } - - // new InternshipType - // { - // Type = "FreeInternship", - // Description = "Praktyka bezpłatna", - // }, - // new InternshipType - // { - // Type = "GraduateInternship" - // }, - // new InternshipType - // { - // Type = "FreeApprenticeship" - // }, - // new InternshipType - // { - // Type = "PaidApprenticeship", - // Description = "np. przemysłowy" - // }, - // new InternshipType - // { - // Type = "ForeignInternship", - // Description = "np. IAESTE, ERASMUS" - // }, - // new InternshipType - // { - // Type = "UOP" - // }, - // new InternshipType - // { - // Type = "UD" - // }, - // new InternshipType - // { - // Type = "UZ" - // }, - // new InternshipType - // { - // Type = "Other", - // Description = "Należy wprowadzić samodzielnie" - // } } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs index f95f1f5..9ff73e3 100644 --- a/src/InternshipSystem.Repository/InternshipDbContext.cs +++ b/src/InternshipSystem.Repository/InternshipDbContext.cs @@ -10,6 +10,7 @@ namespace InternshipSystem.Repository public DbSet Companies { get; set; } public DbSet Editions { get; set; } public DbSet StaticPages { get; set; } + public DbSet InternshipTypes { get; set; } public DbSet Students { get; set; } public InternshipDbContext(DbContextOptions options) From 7b7998f40868ed60f887ba122c9b013a166ffc3f Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 12 Sep 2020 16:49:44 +0200 Subject: [PATCH 3/5] fixes --- src/InternshipSystem.Api/Controllers/AccessController.cs | 2 +- .../Controllers/DocumentsController.cs | 7 +++---- .../Controllers/EditionController.cs | 8 +++----- .../Controllers/InternshipRegistrationController.cs | 8 +++----- .../Controllers/InternshipTypesController.cs | 5 +++-- .../Controllers/RegistrationController.cs | 8 +++----- src/InternshipSystem.Api/ModelBinders/UserBinder.cs | 9 ++++++++- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/AccessController.cs b/src/InternshipSystem.Api/Controllers/AccessController.cs index 44d1b95..ea15e8f 100644 --- a/src/InternshipSystem.Api/Controllers/AccessController.cs +++ b/src/InternshipSystem.Api/Controllers/AccessController.cs @@ -44,7 +44,7 @@ namespace InternshipSystem.Api.Controllers [HttpGet("loginEdition")] [Authorize] - public async Task LoginIntoEdition(Guid editionId, User user, CancellationToken token) + public async Task LoginIntoEdition(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 3406f9b..033b2aa 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -35,7 +35,8 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [Authorize(Policy = Policies.RegisteredOnly)] - public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest, CancellationToken cancellationToken) + public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest, + [FromServices] User user, CancellationToken cancellationToken) { var validator = new DocumentPublishRequest.Validator(); var validationResult = await validator.ValidateAsync(documentRequest, cancellationToken); @@ -45,9 +46,7 @@ namespace InternshipSystem.Api.Controllers return BadRequest(validationResult.ToString()); } - var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - - return await _internshipService.AddDocumentToInternship(documentRequest, personNumber, cancellationToken); + return await _internshipService.AddDocumentToInternship(documentRequest, user.PersonNumber, cancellationToken); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/EditionController.cs b/src/InternshipSystem.Api/Controllers/EditionController.cs index f9e6774..777524c 100644 --- a/src/InternshipSystem.Api/Controllers/EditionController.cs +++ b/src/InternshipSystem.Api/Controllers/EditionController.cs @@ -38,15 +38,13 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [Authorize] - public async Task>> GetAvailableEditions(CancellationToken token) + public async Task>> GetAvailableEditions([FromServices] User user, CancellationToken token) { - var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - var editions = await Context.Editions .Where(edition => edition.Internships - .Any(internship => internship.Student.Id == personNumber)) + .Any(internship => internship.Student.Id == user.PersonNumber)) .ProjectTo(Mapper.ConfigurationProvider) .ToListAsync(token); @@ -74,7 +72,7 @@ namespace InternshipSystem.Api.Controllers var edition = await Context.Editions .Include(e => e.AvailableSubjects) - .Where(e => e.Id == id) + .Where(e => e.Id.Equals(id)) .ProjectTo(Mapper.ConfigurationProvider) .FirstOrDefaultAsync(token); diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 44c8eb6..6bc7ab8 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -31,8 +31,8 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [Authorize] - public async Task SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, - CancellationToken cancellationToken) + public async Task SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, + [FromServices] User user, CancellationToken cancellationToken) { var validator = new RegistrationFormQuery.Validator(); var validationResult = await validator.ValidateAsync(registrationQuery, cancellationToken); @@ -41,10 +41,8 @@ namespace InternshipSystem.Api.Controllers { return BadRequest(validationResult.ToString()); } - - var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - return await _internshipService.SubmitRegistration(registrationQuery, personNumber, cancellationToken); + return await _internshipService.SubmitRegistration(registrationQuery, user.PersonNumber, cancellationToken); } } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs index d4afa36..f7a77dd 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -41,7 +42,7 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [Authorize] + [Authorize(Policy = Policies.RegisteredOnly)] public async Task>> GetInternshipTypesForEdition([FromServices] User user, CancellationToken cancellationToken) { var edition = diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index 89d2cb2..f5de0b1 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -33,7 +33,7 @@ namespace InternshipSystem.Api.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] [Authorize] - public async Task RegisterStudentForEdition([FromBody] Guid registrationCode, CancellationToken token) + public async Task RegisterStudentForEdition([FromBody] Guid registrationCode, [FromServices] User user, CancellationToken token) { var edition = await _context.Editions.FindAsync(registrationCode, token); @@ -41,10 +41,8 @@ namespace InternshipSystem.Api.Controllers { return NotFound(); } - - var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); - - var student = await _context.Students.FindAsync(personNumber, token); + + var student = await _context.Students.FindAsync(user.PersonNumber, token); edition.RegisterInternship(student); await _context.SaveChangesAsync(token); diff --git a/src/InternshipSystem.Api/ModelBinders/UserBinder.cs b/src/InternshipSystem.Api/ModelBinders/UserBinder.cs index 8a5fe2a..62096e2 100644 --- a/src/InternshipSystem.Api/ModelBinders/UserBinder.cs +++ b/src/InternshipSystem.Api/ModelBinders/UserBinder.cs @@ -22,12 +22,19 @@ namespace InternshipSystem.Api.ModelBinders { return Task.CompletedTask; } + + Guid? editionGuid = null; + if (principal.FindFirst(InternshipClaims.Edition) != null + && Guid.TryParse(principal.FindFirst(InternshipClaims.Edition).Value, out var edition)) + { + editionGuid = edition; + } var user = new User { Name = principal.FindFirst(ClaimTypes.Name).Value, PersonNumber = long.Parse(principal.FindFirst(InternshipClaims.PersonNumber).Value), - EditionId = Guid.TryParse(principal.FindFirst(InternshipClaims.Edition).Value, out var edition) ? edition : (Guid?) null + EditionId = editionGuid }; bindingContext.Result = ModelBindingResult.Success(user); From c89229d1a97efa61c4ddd326c9193adfe944a040 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 12 Sep 2020 17:18:35 +0200 Subject: [PATCH 4/5] Rewrite Nip and PhoneNumber --- .../Controllers/InternshipTypesController.cs | 12 +----------- src/InternshipSystem.Core/Entity/Company.cs | 5 ++--- .../Entity/Internship/InternshipSubject.cs | 1 + .../Entity/Internship/InternshipType.cs | 1 + .../Entity/StaticPage.cs | 2 ++ .../ValueObject/Mentor.cs | 2 +- src/InternshipSystem.Core/ValueObject/Nip.cs | 18 ------------------ .../ValueObject/PhoneNumber.cs | 18 ------------------ .../DatabaseFiller.cs | 19 +++++++++++++++---- .../InternshipDbContext.cs | 12 +----------- 10 files changed, 24 insertions(+), 66 deletions(-) delete mode 100644 src/InternshipSystem.Core/ValueObject/Nip.cs delete mode 100644 src/InternshipSystem.Core/ValueObject/PhoneNumber.cs diff --git a/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs index f7a77dd..e7ac0df 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipTypesController.cs @@ -24,21 +24,11 @@ namespace InternshipSystem.Api.Controllers } private InternshipDbContext Context { get; } - /// - /// Get all internship types - /// - /// List of internship types - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> GetAllInternshipTypes(CancellationToken cancellationToken) => - await Context.InternshipTypes - .ToListAsync(cancellationToken); - /// /// Get static page /// /// List of internship types for edition - [HttpGet("forCurrentEdition")] + [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] diff --git a/src/InternshipSystem.Core/Entity/Company.cs b/src/InternshipSystem.Core/Entity/Company.cs index 67b640d..46904c4 100644 --- a/src/InternshipSystem.Core/Entity/Company.cs +++ b/src/InternshipSystem.Core/Entity/Company.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace InternshipSystem.Core { public class Company { public long Id { get; set; } - public Nip Nip { get; set; } + public string Nip { get; set; } public string Name { get; set; } public List Branches { get; set; } diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipSubject.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipSubject.cs index f94b0c9..f6c312b 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipSubject.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipSubject.cs @@ -5,5 +5,6 @@ public long Id { get; set; } public string Description { get; set; } + public string DescriptionEng { get; set; } } } \ 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 5065f12..0056c4a 100644 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs +++ b/src/InternshipSystem.Core/Entity/Internship/InternshipType.cs @@ -5,5 +5,6 @@ public long Id { get; set; } public string Type { get; set; } public string Description { get; set; } + public string DescriptionEng { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/StaticPage.cs b/src/InternshipSystem.Core/Entity/StaticPage.cs index b4329bd..56b474c 100644 --- a/src/InternshipSystem.Core/Entity/StaticPage.cs +++ b/src/InternshipSystem.Core/Entity/StaticPage.cs @@ -5,6 +5,8 @@ public long Id { get; set; } public string AccessName { get; set; } public string Title { get; set; } + public string TitleEng { get; set; } public string Content { get; set; } + public string ContentEng { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/ValueObject/Mentor.cs b/src/InternshipSystem.Core/ValueObject/Mentor.cs index 4af5c24..d7be213 100644 --- a/src/InternshipSystem.Core/ValueObject/Mentor.cs +++ b/src/InternshipSystem.Core/ValueObject/Mentor.cs @@ -5,6 +5,6 @@ public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } - public PhoneNumber PhoneNumber { get; set; } + public string PhoneNumber { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/ValueObject/Nip.cs b/src/InternshipSystem.Core/ValueObject/Nip.cs deleted file mode 100644 index 903b59e..0000000 --- a/src/InternshipSystem.Core/ValueObject/Nip.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace InternshipSystem.Core -{ - public struct Nip - { - private readonly string _nip; - - public Nip(string nip) - { - _nip = nip; - } - - public static implicit operator string(Nip nip) => - nip._nip; - - public static implicit operator Nip(string maybeNip) => - new Nip(maybeNip); - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Core/ValueObject/PhoneNumber.cs b/src/InternshipSystem.Core/ValueObject/PhoneNumber.cs deleted file mode 100644 index e72d355..0000000 --- a/src/InternshipSystem.Core/ValueObject/PhoneNumber.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace InternshipSystem.Core -{ - public struct PhoneNumber - { - private readonly string _phoneNumber; - - public PhoneNumber(string phoneNumber) - { - _phoneNumber = phoneNumber; - } - - public static implicit operator string(PhoneNumber number) => - number._phoneNumber; - - public static implicit operator PhoneNumber(string maybeNumber) => - new PhoneNumber(maybeNumber); - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index bbb1693..0d07a43 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -110,41 +110,49 @@ namespace InternshipSystem.Repository { Type = "FreeInternship", Description = "Praktyka bezpłatna", + DescriptionEng = "Free internship", }, new InternshipType { Type = "GraduateInternship", Description = "Praktyka absolwencka", + DescriptionEng = "Graduate internship", }, new InternshipType { Type = "FreeApprenticeship", Description = "Praktyka bezpłatna", + DescriptionEng = "Free apprenticeship", }, new InternshipType { Type = "PaidApprenticeship", Description = "np. przemysłowy", + DescriptionEng = "Paid apprenticeship", }, new InternshipType { Type = "ForeignInternship", Description = "np. IAESTE, ERASMUS", + DescriptionEng = "Foreign internship", }, new InternshipType { Type = "UOP", Description = "umowa o pracę", + DescriptionEng = "contract of employment", }, new InternshipType { Type = "UD", Description = "umowa o dzieło", + DescriptionEng = "contract work", }, new InternshipType { Type = "UZ", Description = "umowa zlecenie", + DescriptionEng = "contract of mandate" }, }; await Context.InternshipTypes.AddRangeAsync(internshipTypes); @@ -167,21 +175,24 @@ namespace InternshipSystem.Repository { Subject = new InternshipSubject { - Description = "Modelowanie baz danych" + Description = "Modelowanie baz danych", + DescriptionEng = "Database modeling", } }, new EditionSubject { Subject = new InternshipSubject { - Description = "Oprogramowywanie kart graficznych" + Description = "Oprogramowywanie kart graficznych", + DescriptionEng = "Graphics card software", } }, new EditionSubject { Subject = new InternshipSubject { - Description = "Projektowanie UI" + Description = "Projektowanie UI", + DescriptionEng = "UI design", } } }, @@ -315,7 +326,7 @@ namespace InternshipSystem.Repository "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quare ad ea primum, si videtur; Duo Reges: constructio interrete. Eam tum adesse, cum dolor omnis absit; Sed ad bona praeterita redeamus. Facillimum id quidem est, inquam. Apud ceteros autem philosophos, qui quaesivit aliquid, tacet;

" + "

Quorum altera prosunt, nocent altera. Eam stabilem appellas. Sed nimis multa. Quo plebiscito decreta a senatu est consuli quaestio Cn. Sin laboramus, quis est, qui alienae modum statuat industriae? Quod quidem nobis non saepe contingit. Si autem id non concedatur, non continuo vita beata tollitur. " + "Illum mallem levares, quo optimum atque humanissimum virum, Cn. Id est enim, de quo quaerimus.

Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Sin dicit obscurari quaedam nec apparere, quia valde parva sint, nos quoque concedimus; Et quod est munus, quod opus sapientiae? Ab hoc autem quaedam non melius quam veteres, quaedam omnino relicta.

" + - "Prosto spod bazy ;D" + "

Prosto spod bazy ;D

" }, new StaticPage { diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs index 9ff73e3..0e729fb 100644 --- a/src/InternshipSystem.Repository/InternshipDbContext.cs +++ b/src/InternshipSystem.Repository/InternshipDbContext.cs @@ -24,21 +24,11 @@ namespace InternshipSystem.Repository protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity() - .Property(company => company.Nip) - .HasConversion( - nip => nip, - s => (Nip)s); - modelBuilder.Entity() .OwnsOne(bo => bo.Address); modelBuilder.Entity() - .OwnsOne(ip => ip.Mentor) - .Property(mentor => mentor.PhoneNumber) - .HasConversion( - number => number, - s => (PhoneNumber)s); + .OwnsOne(ip => ip.Mentor); modelBuilder.Entity(builder => { From 5884a444a92b7de9e90eb7ad568bc611d94412fb Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Sat, 12 Sep 2020 17:23:51 +0200 Subject: [PATCH 5/5] eng static pages fill --- src/InternshipSystem.Repository/DatabaseFiller.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 0d07a43..f6038a8 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -322,18 +322,27 @@ namespace InternshipSystem.Repository { AccessName = "regulations", Title = "Regulamin Praktyk", + TitleEng = "Internship Regulations", Content = "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quare ad ea primum, si videtur; Duo Reges: constructio interrete. Eam tum adesse, cum dolor omnis absit; Sed ad bona praeterita redeamus. Facillimum id quidem est, inquam. Apud ceteros autem philosophos, qui quaesivit aliquid, tacet;

" + "

Quorum altera prosunt, nocent altera. Eam stabilem appellas. Sed nimis multa. Quo plebiscito decreta a senatu est consuli quaestio Cn. Sin laboramus, quis est, qui alienae modum statuat industriae? Quod quidem nobis non saepe contingit. Si autem id non concedatur, non continuo vita beata tollitur. " + "Illum mallem levares, quo optimum atque humanissimum virum, Cn. Id est enim, de quo quaerimus.

Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Sin dicit obscurari quaedam nec apparere, quia valde parva sint, nos quoque concedimus; Et quod est munus, quod opus sapientiae? Ab hoc autem quaedam non melius quam veteres, quaedam omnino relicta.

" + - "

Prosto spod bazy ;D

" + "

Prosto z bazy danych ;D

", + ContentEng = + "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quare ad ea primum, si videtur; Duo Reges: constructio interrete. Eam tum adesse, cum dolor omnis absit; Sed ad bona praeterita redeamus. Facillimum id quidem est, inquam. Apud ceteros autem philosophos, qui quaesivit aliquid, tacet;

" + + "

Quorum altera prosunt, nocent altera. Eam stabilem appellas. Sed nimis multa. Quo plebiscito decreta a senatu est consuli quaestio Cn. Sin laboramus, quis est, qui alienae modum statuat industriae? Quod quidem nobis non saepe contingit. Si autem id non concedatur, non continuo vita beata tollitur. " + + "Illum mallem levares, quo optimum atque humanissimum virum, Cn. Id est enim, de quo quaerimus.

Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Sin dicit obscurari quaedam nec apparere, quia valde parva sint, nos quoque concedimus; Et quod est munus, quod opus sapientiae? Ab hoc autem quaedam non melius quam veteres, quaedam omnino relicta.

" + + "

Straight from the database ;D

", }, new StaticPage { AccessName = "info", Title = "Informacje", + TitleEng = "Information", Content = - "

Nowe zmiany:

" + "

Nowe zmiany:

", + ContentEng = + "

New changes:

", } }; await Context.StaticPages.AddRangeAsync(staticPages);