Kurwa
This commit is contained in:
parent
ea94789167
commit
caf91f77ee
@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InternshipSystem.Api.Commands;
|
using InternshipSystem.Api.Commands;
|
||||||
@ -35,7 +36,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
[Authorize(Policy = Policies.RegisteredOnly)]
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||||
public async Task<ActionResult> SubmitRegistrationForm(
|
public async Task<ActionResult> SubmitRegistrationForm(
|
||||||
UpdateRegistrationForm registrationCommand,
|
[FromBody] UpdateRegistrationForm registrationCommand,
|
||||||
[FromServices] User user,
|
[FromServices] User user,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@ -51,22 +52,36 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
.Entry(edition)
|
.Entry(edition)
|
||||||
.Collection(e => e.Internships)
|
.Collection(e => e.Internships)
|
||||||
.Query()
|
.Query()
|
||||||
|
.Include(i => i.InternshipRegistration)
|
||||||
|
.ThenInclude(r => r.BranchAddress)
|
||||||
|
.Include(i => i.InternshipRegistration)
|
||||||
|
.ThenInclude(r => r.Company)
|
||||||
|
.Include(i => i.InternshipRegistration)
|
||||||
|
.ThenInclude(c => c.Company.Branches)
|
||||||
|
.Include(i => i.InternshipRegistration)
|
||||||
|
.ThenInclude(c => c.Type)
|
||||||
|
.Include(i => i.InternshipRegistration)
|
||||||
|
.ThenInclude(c => c.Subjects)
|
||||||
.Where(i => i.Student.Id == user.PersonNumber)
|
.Where(i => i.Student.Id == user.PersonNumber)
|
||||||
.Select(i => i.InternshipRegistration)
|
.Select(i => i.InternshipRegistration)
|
||||||
.Include(r => r.BranchAddress)
|
|
||||||
.Include(r => r.Type)
|
|
||||||
.Include(r => r.Subjects)
|
|
||||||
.Include(r => r.Company)
|
|
||||||
.Include(r => r.Company.Branches)
|
|
||||||
.FirstAsync(cancellationToken);
|
.FirstAsync(cancellationToken);
|
||||||
|
|
||||||
|
|
||||||
var useCase = new UpdateInternshipRegistrationUseCase(_context, internshipRegistration, edition, user);
|
var useCase = new UpdateInternshipRegistrationUseCase(_context, internshipRegistration, edition, user);
|
||||||
|
|
||||||
var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
|
||||||
|
|
||||||
await _context.SaveChangesAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Ok(result);
|
try
|
||||||
|
{
|
||||||
|
var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (ArgumentException e)
|
||||||
|
{
|
||||||
|
return BadRequest(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -92,7 +107,6 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
.Include(i => i.Documentation)
|
.Include(i => i.Documentation)
|
||||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
internship.Edition = null;
|
|
||||||
return Ok(internship);
|
return Ok(internship);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||||
<PackageReference Include="FluentValidation" Version="9.1.2" />
|
<PackageReference Include="FluentValidation" Version="9.1.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.6" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.6" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8"/>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
||||||
<PackageReference Include="Serilog" Version="2.9.0" />
|
<PackageReference Include="Serilog" Version="2.9.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||||
|
@ -16,6 +16,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace InternshipSystem.Api
|
namespace InternshipSystem.Api
|
||||||
{
|
{
|
||||||
@ -46,7 +47,7 @@ namespace InternshipSystem.Api
|
|||||||
.AddScoped<IInternshipService, InternshipService>()
|
.AddScoped<IInternshipService, InternshipService>()
|
||||||
.AddScoped<JwtTokenService>()
|
.AddScoped<JwtTokenService>()
|
||||||
.AddAutoMapper(cfg => cfg.AddProfile<ApiProfile>());
|
.AddAutoMapper(cfg => cfg.AddProfile<ApiProfile>());
|
||||||
|
|
||||||
services
|
services
|
||||||
.AddSwaggerGen(options =>
|
.AddSwaggerGen(options =>
|
||||||
{
|
{
|
||||||
@ -55,7 +56,8 @@ namespace InternshipSystem.Api
|
|||||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||||
options.IncludeXmlComments(xmlPath);
|
options.IncludeXmlComments(xmlPath);
|
||||||
})
|
})
|
||||||
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); });
|
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); })
|
||||||
|
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -84,6 +85,8 @@ namespace InternshipSystem.Api.UseCases
|
|||||||
|
|
||||||
company.Name = companyUpdate.Name ?? company.Name;
|
company.Name = companyUpdate.Name ?? company.Name;
|
||||||
company.Nip = companyUpdate.Nip ?? company.Nip;
|
company.Nip = companyUpdate.Nip ?? company.Nip;
|
||||||
|
|
||||||
|
subjectRegistration.BranchAddress = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (companyUpdate.BranchOffice.HasValue)
|
if (companyUpdate.BranchOffice.HasValue)
|
||||||
@ -122,6 +125,12 @@ namespace InternshipSystem.Api.UseCases
|
|||||||
|
|
||||||
private void UpdateSubjects(IEnumerable<long> subjects)
|
private void UpdateSubjects(IEnumerable<long> subjects)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (!_edition.AreSubjectsAvailable(subjects))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("subjects chosen are not available in this edition");
|
||||||
|
}
|
||||||
|
|
||||||
subjectRegistration.Subjects =
|
subjectRegistration.Subjects =
|
||||||
subjects
|
subjects
|
||||||
.Select(i => new ProgramSubject
|
.Select(i => new ProgramSubject
|
||||||
|
@ -49,11 +49,9 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
.SetValidator(new Mentor.Validate())
|
.SetValidator(new Mentor.Validate())
|
||||||
.NotNull();
|
.NotNull();
|
||||||
RuleFor(x => x.Subjects)
|
RuleFor(x => x.Subjects)
|
||||||
.NotEmpty()
|
.NotEmpty();
|
||||||
.Must(s => edition.AreSubjectsAvailable(s.Select(su => su.InternshipSubjectId)));
|
|
||||||
RuleFor(x => x.Type)
|
RuleFor(x => x.Type)
|
||||||
.NotNull()
|
.NotNull();
|
||||||
.Must(edition.IsTypeAvailable);
|
|
||||||
RuleFor(x => x.Start)
|
RuleFor(x => x.Start)
|
||||||
.GreaterThanOrEqualTo(edition.EditionStart)
|
.GreaterThanOrEqualTo(edition.EditionStart)
|
||||||
.LessThan(x => x.End)
|
.LessThan(x => x.End)
|
||||||
|
Loading…
Reference in New Issue
Block a user