LOOOOOOOOOOOOL
This commit is contained in:
parent
54dfcaa7e7
commit
d3691fb0a8
@ -42,15 +42,9 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
public async Task<ActionResult> Authenticate(string code, CancellationToken cancellationToken)
|
public async Task<ActionResult> Authenticate(string code, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var token = await _loginClient.GetCasTokenAsync(code, cancellationToken);
|
var token = await _loginClient.GetCasTokenAsync(code, cancellationToken);
|
||||||
|
|
||||||
var casData = await _loginClient.GetProfileAsync(token, cancellationToken);
|
var casData = await _loginClient.GetProfileAsync(token, cancellationToken);
|
||||||
|
|
||||||
if (!long.TryParse(casData.PersonNumber, out var id))
|
var student = await _context.Students.FirstOrDefaultAsync(s => s.Id == long.Parse(casData.PersonNumber));
|
||||||
{
|
|
||||||
return BadRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
var student = await _context.Students.FirstOrDefaultAsync(s => s.Id == id);
|
|
||||||
|
|
||||||
if (student == null)
|
if (student == null)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
new JsonSerializerOptions
|
new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true
|
PropertyNameCaseInsensitive = true
|
||||||
});
|
}, cancellationToken);
|
||||||
|
|
||||||
return result.Attributes;
|
return result.Attributes;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InternshipSystem.Api.Queries;
|
|
||||||
using InternshipSystem.Api.Security;
|
using InternshipSystem.Api.Security;
|
||||||
using InternshipSystem.Core.Commands;
|
using InternshipSystem.Core.Commands;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using InternshipSystem.Api.Security;
|
|
||||||
using InternshipSystem.Api.Services;
|
using InternshipSystem.Api.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -18,10 +15,12 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
public class InternshipRegistrationController : ControllerBase
|
public class InternshipRegistrationController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IInternshipService _internshipService;
|
private readonly IInternshipService _internshipService;
|
||||||
|
private readonly InternshipDbContext _context;
|
||||||
|
|
||||||
public InternshipRegistrationController(IInternshipService internshipService)
|
public InternshipRegistrationController(IInternshipService internshipService, InternshipDbContext context)
|
||||||
{
|
{
|
||||||
_internshipService = internshipService;
|
_internshipService = internshipService;
|
||||||
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -35,19 +34,21 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
[Authorize]
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||||
public async Task<ActionResult> SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery,
|
public async Task<ActionResult> SubmitRegistrationForm(
|
||||||
[FromServices] User user, CancellationToken cancellationToken)
|
[FromBody] UpdateRegistrationForm registrationQuery,
|
||||||
|
[FromServices] User user,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var validator = new RegistrationFormQuery.Validator();
|
var edition = await _context.Editions.FirstAsync(e => e.Id == user.EditionId, cancellationToken);
|
||||||
var validationResult = await validator.ValidateAsync(registrationQuery, cancellationToken);
|
|
||||||
|
|
||||||
if (!validationResult.IsValid)
|
var internship = await _context
|
||||||
{
|
.Entry(edition)
|
||||||
return BadRequest(validationResult.ToString());
|
.Collection(e => e.Internships)
|
||||||
}
|
.Query()
|
||||||
|
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
return await _internshipService.SubmitRegistration(registrationQuery, user.PersonNumber, cancellationToken);
|
internship.UpdateInternshipRegistration(registrationQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using InternshipSystem.Core.Entity.Internship;
|
using InternshipSystem.Core.Entity.Internship;
|
||||||
|
|
||||||
namespace InternshipSystem.Core.Commands
|
namespace InternshipSystem.Core.Commands
|
||||||
@ -8,7 +9,17 @@ namespace InternshipSystem.Core.Commands
|
|||||||
public UpdateCompany? Company { get; set; }
|
public UpdateCompany? Company { get; set; }
|
||||||
public DateTime? Start { get; set; }
|
public DateTime? Start { get; set; }
|
||||||
public DateTime? End { get; set; }
|
public DateTime? End { get; set; }
|
||||||
public InternshipType? Type { get; set; }
|
public InternshipType Type { get; set; }
|
||||||
|
public UpdateMentor Mentor { get; set; }
|
||||||
|
public List<InternshipSubject> Subjects { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct UpdateMentor
|
||||||
|
{
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct UpdateCompany
|
public struct UpdateCompany
|
||||||
|
@ -44,14 +44,9 @@ namespace InternshipSystem.Core
|
|||||||
Internships.Add(internship);
|
Internships.Add(internship);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDateDuringEdition(DateTime start, DateTime end)
|
public void ValidateInternshipRegistration(InternshipRegistration internshipRegistration)
|
||||||
{
|
{
|
||||||
return start >= EditionStart && end <= EditionFinish;
|
throw new NotImplementedException();
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsInternshiptypeAllowed(InternshipType internshipType)
|
|
||||||
{
|
|
||||||
return AllowedInternshipTypes.HasFlag(internshipType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using InternshipSystem.Core.Commands;
|
using InternshipSystem.Core.Commands;
|
||||||
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
||||||
using InternshipSystem.Core.ValueObject;
|
using InternshipSystem.Core.ValueObject;
|
||||||
|
|
||||||
namespace InternshipSystem.Core
|
namespace InternshipSystem.Core
|
||||||
@ -11,8 +12,8 @@ namespace InternshipSystem.Core
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public Student Student { get; set; }
|
public Student Student { get; set; }
|
||||||
public InternshipRegistration InternshipRegistration { get; set; }
|
public InternshipRegistration InternshipRegistration { get; set; }
|
||||||
public InternshipProgram InternshipProgram { get; set; }
|
|
||||||
public Report Report { get; set; }
|
public Report Report { get; set; }
|
||||||
|
|
||||||
public List<Document> Approvals { get; set; }
|
public List<Document> Approvals { get; set; }
|
||||||
public List<Document> Documentation { get; set; }
|
public List<Document> Documentation { get; set; }
|
||||||
|
|
||||||
@ -44,7 +45,6 @@ namespace InternshipSystem.Core
|
|||||||
internship.Student = student;
|
internship.Student = student;
|
||||||
|
|
||||||
internship.InternshipRegistration = InternshipRegistration.Create();
|
internship.InternshipRegistration = InternshipRegistration.Create();
|
||||||
internship.InternshipProgram = InternshipProgram.Create();
|
|
||||||
internship.Report = Report.Create();
|
internship.Report = Report.Create();
|
||||||
internship.Approvals = new List<Document>();
|
internship.Approvals = new List<Document>();
|
||||||
internship.Documentation = new List<Document>();
|
internship.Documentation = new List<Document>();
|
||||||
@ -54,35 +54,14 @@ namespace InternshipSystem.Core
|
|||||||
|
|
||||||
public void UpdateInternshipRegistration(UpdateRegistrationForm updateRegistration)
|
public void UpdateInternshipRegistration(UpdateRegistrationForm updateRegistration)
|
||||||
{
|
{
|
||||||
var start = updateRegistration.Start ?? InternshipRegistration.Start;
|
InternshipRegistration.UpdateDates(updateRegistration.Start, updateRegistration.End);
|
||||||
var end = updateRegistration.End ?? InternshipRegistration.End;
|
InternshipRegistration.UpdateSubjects(updateRegistration.Subjects);
|
||||||
|
InternshipRegistration.UpdateInternshipType(updateRegistration.Type);
|
||||||
|
|
||||||
if (!Edition.IsDateDuringEdition(start, end))
|
InternshipRegistration.UpdateCompany(updateRegistration.Company);
|
||||||
{
|
InternshipRegistration.UpdateMentor(updateRegistration.Mentor);
|
||||||
throw new ArgumentOutOfRangeException(nameof(InternshipRegistration.Start) + nameof(InternshipRegistration.End),"Date outside of edition boundaries");
|
|
||||||
}
|
|
||||||
|
|
||||||
var internshipType = updateRegistration.Type ?? InternshipRegistration.Type;
|
Edition.ValidateInternshipRegistration(InternshipRegistration);
|
||||||
|
|
||||||
if (!Edition.IsInternshiptypeAllowed(internshipType))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Internship type not allowed for this edition", nameof(updateRegistration.Type));
|
|
||||||
}
|
|
||||||
|
|
||||||
var company = InternshipRegistration.Company;
|
|
||||||
if (company == null)
|
|
||||||
{
|
|
||||||
if (!updateRegistration.Company.HasValue)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Company");
|
|
||||||
}
|
|
||||||
|
|
||||||
company = Company.CreateCompany(updateRegistration.Company.Value);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
InternshipRegistration.Update(start, end, internshipType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using InternshipSystem.Core.Commands;
|
||||||
using InternshipSystem.Core.Entity.Internship;
|
using InternshipSystem.Core.Entity.Internship;
|
||||||
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
||||||
|
|
||||||
namespace InternshipSystem.Core
|
namespace InternshipSystem.Core
|
||||||
{
|
{
|
||||||
@ -10,6 +13,9 @@ namespace InternshipSystem.Core
|
|||||||
public BranchOffice BranchAddress { get; set; }
|
public BranchOffice BranchAddress { get; set; }
|
||||||
public DateTime Start { get; set; }
|
public DateTime Start { get; set; }
|
||||||
public DateTime End { get; set; }
|
public DateTime End { get; set; }
|
||||||
|
public Mentor Mentor { get; set; }
|
||||||
|
|
||||||
|
public List<ProgramSubject> ChosenSubjects { get; set; }
|
||||||
public InternshipType Type { get; set; }
|
public InternshipType Type { get; set; }
|
||||||
public DocumentState State { get; set; }
|
public DocumentState State { get; set; }
|
||||||
|
|
||||||
@ -25,14 +31,29 @@ namespace InternshipSystem.Core
|
|||||||
Type = internshipType;
|
Type = internshipType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCompany(Company newCompany)
|
public void UpdateCompany(UpdateCompany? updateRegistrationCompany)
|
||||||
{
|
{
|
||||||
Company = newCompany;
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateBranch(BranchOffice branch)
|
public void UpdateDates(DateTime? updateRegistrationStart, DateTime? updateRegistrationEnd)
|
||||||
{
|
{
|
||||||
BranchAddress = branch;
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateMentor(UpdateMentor updateRegistrationMentor)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateSubjects(List<InternshipSubject> updateRegistrationSubjects)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateInternshipType(InternshipType updateRegistrationType)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,4 +5,8 @@
|
|||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="FluentValidation" Version="9.1.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -4,8 +4,8 @@ namespace InternshipSystem.Core.UglyOrmArtifacts
|
|||||||
{
|
{
|
||||||
public class ProgramSubject
|
public class ProgramSubject
|
||||||
{
|
{
|
||||||
public long InternshipProgramId { get; set; }
|
public long InternshipId { get; set; }
|
||||||
public InternshipProgram Program { get; set; }
|
public InternshipRegistration InternshipRegistration { get; set; }
|
||||||
public long InternshipSubjectId { get; set; }
|
public long InternshipSubjectId { get; set; }
|
||||||
public InternshipSubject Subject { get; set; }
|
public InternshipSubject Subject { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using FluentValidation.Validators;
|
||||||
|
|
||||||
|
namespace InternshipSystem.Core.Validators
|
||||||
|
{
|
||||||
|
public class InternshipRegistrationValidator : AbstractValidator<InternshipRegistration>
|
||||||
|
{
|
||||||
|
public InternshipRegistrationValidator(Edition edition)
|
||||||
|
{
|
||||||
|
RuleFor(ir => ir.Start)
|
||||||
|
.GreaterThanOrEqualTo(edition.EditionStart)
|
||||||
|
.LessThanOrEqualTo(edition.EditionFinish);
|
||||||
|
|
||||||
|
RuleFor(ir => ir.End)
|
||||||
|
.GreaterThanOrEqualTo(ir => ir.Start)
|
||||||
|
.LessThanOrEqualTo(edition.EditionFinish);
|
||||||
|
|
||||||
|
RuleFor(ir => ir.Company)
|
||||||
|
.SetValidator(new CompanyValidator());
|
||||||
|
|
||||||
|
RuleFor(ir => ir.BranchAddress)
|
||||||
|
.SetValidator(new BranchAddressValidator());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BranchAddressValidator : AbstractValidator<BranchOffice>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CompanyValidator : AbstractValidator<Company>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -237,9 +237,6 @@ namespace InternshipSystem.Repository
|
|||||||
.First(c => c.Name.Equals("Intel"))
|
.First(c => c.Name.Equals("Intel"))
|
||||||
.Branches
|
.Branches
|
||||||
.First(),
|
.First(),
|
||||||
},
|
|
||||||
InternshipProgram = new InternshipProgram
|
|
||||||
{
|
|
||||||
Mentor = new Mentor
|
Mentor = new Mentor
|
||||||
{
|
{
|
||||||
FirstName = "Horacy",
|
FirstName = "Horacy",
|
||||||
@ -286,9 +283,6 @@ namespace InternshipSystem.Repository
|
|||||||
.First(c => c.Name.Equals("Asseco Poland"))
|
.First(c => c.Name.Equals("Asseco Poland"))
|
||||||
.Branches
|
.Branches
|
||||||
.First(),
|
.First(),
|
||||||
},
|
|
||||||
InternshipProgram = new InternshipProgram
|
|
||||||
{
|
|
||||||
Mentor = new Mentor
|
Mentor = new Mentor
|
||||||
{
|
{
|
||||||
FirstName = "Henryk",
|
FirstName = "Henryk",
|
||||||
|
@ -27,18 +27,18 @@ namespace InternshipSystem.Repository
|
|||||||
modelBuilder.Entity<BranchOffice>()
|
modelBuilder.Entity<BranchOffice>()
|
||||||
.OwnsOne(bo => bo.Address);
|
.OwnsOne(bo => bo.Address);
|
||||||
|
|
||||||
modelBuilder.Entity<InternshipProgram>()
|
modelBuilder.Entity<InternshipRegistration>()
|
||||||
.OwnsOne(ip => ip.Mentor);
|
.OwnsOne(ip => ip.Mentor);
|
||||||
|
|
||||||
modelBuilder.Entity<ProgramSubject>(builder =>
|
modelBuilder.Entity<ProgramSubject>(builder =>
|
||||||
{
|
{
|
||||||
builder
|
builder
|
||||||
.HasKey(subject => new { subject.InternshipProgramId, subject.InternshipSubjectId });
|
.HasKey(subject => new {subject.InternshipId, subject.InternshipSubjectId });
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.HasOne(k => k.Program)
|
.HasOne(k => k.InternshipRegistration)
|
||||||
.WithMany(model => model.ChosenSubjects)
|
.WithMany(model => model.ChosenSubjects)
|
||||||
.HasForeignKey(subject => subject.InternshipProgramId);
|
.HasForeignKey(subject => subject.InternshipId);
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.HasOne(k => k.Subject)
|
.HasOne(k => k.Subject)
|
||||||
|
Loading…
Reference in New Issue
Block a user