fix/tytokurwaniepotrafisznicporzadniezrobic (#55)
Merge branch 'master' of http://git.kadet.net/system-praktyk/system-praktyk-api into fix/tytokurwaniepotrafisznicporzadniezrobic KEK Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
parent
3a2b9b64d5
commit
b4b05b7ef3
@ -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,23 +52,37 @@ 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);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
var result = await useCase.UpdateInternshipRegistration(registrationCommand, cancellationToken);
|
||||||
|
|
||||||
await _context.SaveChangesAsync(cancellationToken);
|
await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException e)
|
||||||
|
{
|
||||||
|
return BadRequest(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
@ -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
|
||||||
{
|
{
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user