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.Tasks;
|
||||
using InternshipSystem.Api.Commands;
|
||||
@ -35,7 +36,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||
public async Task<ActionResult> SubmitRegistrationForm(
|
||||
UpdateRegistrationForm registrationCommand,
|
||||
[FromBody] UpdateRegistrationForm registrationCommand,
|
||||
[FromServices] User user,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@ -51,22 +52,36 @@ namespace InternshipSystem.Api.Controllers
|
||||
.Entry(edition)
|
||||
.Collection(e => e.Internships)
|
||||
.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)
|
||||
.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);
|
||||
|
||||
|
||||
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]
|
||||
@ -92,7 +107,6 @@ namespace InternshipSystem.Api.Controllers
|
||||
.Include(i => i.Documentation)
|
||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||
|
||||
internship.Edition = null;
|
||||
return Ok(internship);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="FluentValidation" Version="9.1.2" />
|
||||
<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="Serilog" Version="2.9.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||
|
@ -16,6 +16,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace InternshipSystem.Api
|
||||
{
|
||||
@ -46,7 +47,7 @@ namespace InternshipSystem.Api
|
||||
.AddScoped<IInternshipService, InternshipService>()
|
||||
.AddScoped<JwtTokenService>()
|
||||
.AddAutoMapper(cfg => cfg.AddProfile<ApiProfile>());
|
||||
|
||||
|
||||
services
|
||||
.AddSwaggerGen(options =>
|
||||
{
|
||||
@ -55,7 +56,8 @@ namespace InternshipSystem.Api
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
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)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -84,6 +85,8 @@ namespace InternshipSystem.Api.UseCases
|
||||
|
||||
company.Name = companyUpdate.Name ?? company.Name;
|
||||
company.Nip = companyUpdate.Nip ?? company.Nip;
|
||||
|
||||
subjectRegistration.BranchAddress = null;
|
||||
}
|
||||
|
||||
if (companyUpdate.BranchOffice.HasValue)
|
||||
@ -122,6 +125,12 @@ namespace InternshipSystem.Api.UseCases
|
||||
|
||||
private void UpdateSubjects(IEnumerable<long> subjects)
|
||||
{
|
||||
|
||||
if (!_edition.AreSubjectsAvailable(subjects))
|
||||
{
|
||||
throw new ArgumentException("subjects chosen are not available in this edition");
|
||||
}
|
||||
|
||||
subjectRegistration.Subjects =
|
||||
subjects
|
||||
.Select(i => new ProgramSubject
|
||||
|
Loading…
Reference in New Issue
Block a user