feat/authorization #39
@ -88,6 +88,5 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
|
|
||||||
return Ok(edition);
|
return Ok(edition);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,9 +2,13 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InternshipSystem.Api.Queries;
|
using InternshipSystem.Api.Queries;
|
||||||
|
using InternshipSystem.Api.Security;
|
||||||
|
using InternshipSystem.Core.Commands;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Controllers
|
namespace InternshipSystem.Api.Controllers
|
||||||
{
|
{
|
||||||
@ -21,7 +25,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validate and add filled internship registration form
|
/// Validate and add filled internship registration form
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="registrationQuery">Internship registration data</param>
|
/// <param name="updateRegistration">Internship registration data</param>
|
||||||
/// <response code="200">If registration form was successfully added</response>
|
/// <response code="200">If registration form was successfully added</response>
|
||||||
/// <response code="400">If the provided registration query was malformed</response>
|
/// <response code="400">If the provided registration query was malformed</response>
|
||||||
/// <response code="401">This action is only available for authorized student registered for current edition</response>
|
/// <response code="401">This action is only available for authorized student registered for current edition</response>
|
||||||
@ -29,7 +33,21 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
public async Task<ActionResult> SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, CancellationToken cancellationToken) =>
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||||
throw new NotImplementedException();
|
public async Task<ActionResult> SubmitRegistrationForm(
|
||||||
|
[FromBody] UpdateRegistrationForm updateRegistration,
|
||||||
|
User user,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var edition = await Context.Editions.FindAsync(user.EditionId.Value);
|
||||||
|
|
||||||
|
var internship = await Context
|
||||||
|
.Entry(edition)
|
||||||
|
.Collection(e => e.Internships)
|
||||||
|
.Query()
|
||||||
|
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
|
internship.UpdateInternshipRegistration(updateRegistration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,7 +47,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
var student = await _context.Students.FindAsync(user.PersonNumber);
|
var student = await _context.Students.FindAsync(user.PersonNumber);
|
||||||
|
|
||||||
edition.RegisterInternship(student);
|
edition.RegisterInternship(student);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync(token);
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using InternshipSystem.Core;
|
|
||||||
using InternshipSystem.Core.Entity.Internship;
|
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Queries
|
|
||||||
{
|
|
||||||
public class RegistrationFormQuery
|
|
||||||
{
|
|
||||||
public Company Company { get; set; }
|
|
||||||
public BranchOffice BranchAddress { get; set; }
|
|
||||||
public DateTime Start { get; set; }
|
|
||||||
public DateTime End { get; set; }
|
|
||||||
public InternshipType Type { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
33
src/InternshipSystem.Core/Commands/UpdateRegistrationForm.cs
Normal file
33
src/InternshipSystem.Core/Commands/UpdateRegistrationForm.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using InternshipSystem.Core.Entity.Internship;
|
||||||
|
|
||||||
|
namespace InternshipSystem.Core.Commands
|
||||||
|
{
|
||||||
|
public class UpdateRegistrationForm
|
||||||
|
{
|
||||||
|
public UpdateCompany? Company { get; set; }
|
||||||
|
public DateTime? Start { get; set; }
|
||||||
|
public DateTime? End { get; set; }
|
||||||
|
public InternshipType? Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct UpdateCompany
|
||||||
|
{
|
||||||
|
public long? Id { get; set; }
|
||||||
|
public string Nip { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public UpdateBranchOffice? BranchOffice { get; set; }
|
||||||
|
|
||||||
|
public bool IsUpdate => Id.HasValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct UpdateBranchOffice
|
||||||
|
{
|
||||||
|
public long? Id { get; set; }
|
||||||
|
public string Street { get; set; }
|
||||||
|
public string Building { get; set; }
|
||||||
|
public string City { get; set; }
|
||||||
|
public string PostalCode { get; set; }
|
||||||
|
public string Country { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using InternshipSystem.Core.Commands;
|
||||||
|
|
||||||
namespace InternshipSystem.Core
|
namespace InternshipSystem.Core
|
||||||
{
|
{
|
||||||
@ -8,16 +8,13 @@ namespace InternshipSystem.Core
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public Nip Nip { get; set; }
|
public Nip Nip { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public RangeOfActivity Range { get; set; }
|
|
||||||
public List<BranchOffice> Branches { get; set; }
|
public List<BranchOffice> Branches { get; set; }
|
||||||
public Uri SiteAddress { get; set; }
|
|
||||||
|
|
||||||
public Company CreateCompany(string nip, RangeOfActivity range, string name)
|
public Company CreateCompany(string nip, string name)
|
||||||
{
|
{
|
||||||
return new Company
|
return new Company
|
||||||
{
|
{
|
||||||
Nip = nip,
|
Nip = nip,
|
||||||
Range = range,
|
|
||||||
Name = name
|
Name = name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -25,5 +22,9 @@ namespace InternshipSystem.Core
|
|||||||
public void AddBranchAddress(BranchAddress branch)
|
public void AddBranchAddress(BranchAddress branch)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Company CreateCompany(UpdateCompany updateCompany)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,6 +13,9 @@ namespace InternshipSystem.Core
|
|||||||
public DateTime ReportingStart { get; set; }
|
public DateTime ReportingStart { get; set; }
|
||||||
public Course Course { get; set; }
|
public Course Course { get; set; }
|
||||||
public List<Internship> Internships { get; set; }
|
public List<Internship> Internships { get; set; }
|
||||||
|
|
||||||
|
public InternshipType AllowedInternshipTypes { get; set; }
|
||||||
|
|
||||||
public List<EditionSubject> AvailableSubjects { get; set; }
|
public List<EditionSubject> AvailableSubjects { get; set; }
|
||||||
|
|
||||||
public bool IsOpen => EditionFinish < DateTime.Today;
|
public bool IsOpen => EditionFinish < DateTime.Today;
|
||||||
@ -33,5 +36,15 @@ namespace InternshipSystem.Core
|
|||||||
|
|
||||||
Internships.Add(internship);
|
Internships.Add(internship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDateDuringEdition(DateTime start, DateTime end)
|
||||||
|
{
|
||||||
|
return start >= EditionStart && end <= EditionFinish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsInternshiptypeAllowed(InternshipType internshipType)
|
||||||
|
{
|
||||||
|
return AllowedInternshipTypes.HasFlag(internshipType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using InternshipSystem.Core.Commands;
|
||||||
using InternshipSystem.Core.ValueObject;
|
using InternshipSystem.Core.ValueObject;
|
||||||
|
|
||||||
namespace InternshipSystem.Core
|
namespace InternshipSystem.Core
|
||||||
@ -13,6 +15,9 @@ namespace InternshipSystem.Core
|
|||||||
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; }
|
||||||
|
|
||||||
|
public Edition Edition { get; set; }
|
||||||
|
|
||||||
public float? Grade { get; set; }
|
public float? Grade { get; set; }
|
||||||
|
|
||||||
public void UpdateDocument(Document document)
|
public void UpdateDocument(Document document)
|
||||||
@ -46,5 +51,38 @@ namespace InternshipSystem.Core
|
|||||||
|
|
||||||
return internship;
|
return internship;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateInternshipRegistration(UpdateRegistrationForm updateRegistration)
|
||||||
|
{
|
||||||
|
var start = updateRegistration.Start ?? InternshipRegistration.Start;
|
||||||
|
var end = updateRegistration.End ?? InternshipRegistration.End;
|
||||||
|
|
||||||
|
if (!Edition.IsDateDuringEdition(start, end))
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(InternshipRegistration.Start) + nameof(InternshipRegistration.End),"Date outside of edition boundaries");
|
||||||
|
}
|
||||||
|
|
||||||
|
var internshipType = updateRegistration.Type ?? InternshipRegistration.Type;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,5 +17,12 @@ namespace InternshipSystem.Core
|
|||||||
{
|
{
|
||||||
return new InternshipRegistration();
|
return new InternshipRegistration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(DateTime start, DateTime end, InternshipType internshipType)
|
||||||
|
{
|
||||||
|
Start = start;
|
||||||
|
End = end;
|
||||||
|
Type = internshipType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,12 @@
|
|||||||
namespace InternshipSystem.Core.Entity.Internship
|
using System;
|
||||||
|
|
||||||
|
namespace InternshipSystem.Core.Entity.Internship
|
||||||
{
|
{
|
||||||
public class InternshipType
|
[Flags]
|
||||||
|
public enum InternshipType : long
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
None,
|
||||||
public string Type { get; set; }
|
UOP,
|
||||||
public string Description { get; set; }
|
UOZ
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,13 @@
|
|||||||
namespace InternshipSystem.Core
|
using System;
|
||||||
|
|
||||||
|
namespace InternshipSystem.Core
|
||||||
{
|
{
|
||||||
public class Report
|
public class Report
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public DocumentState State { get; set; }
|
public DocumentState State { get; set; }
|
||||||
|
public RangeOfActivity Range { get; set; }
|
||||||
|
public Uri SiteAddress { get; set; }
|
||||||
|
|
||||||
public static Report Create()
|
public static Report Create()
|
||||||
{
|
{
|
||||||
|
@ -162,10 +162,7 @@ namespace InternshipSystem.Repository
|
|||||||
InternshipRegistration = new InternshipRegistration
|
InternshipRegistration = new InternshipRegistration
|
||||||
{
|
{
|
||||||
Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel
|
Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel
|
||||||
Type = new InternshipType
|
Type = InternshipType.UOP,
|
||||||
{
|
|
||||||
Type = "UOP"
|
|
||||||
},
|
|
||||||
Start = new DateTime(2000, 7, 1),
|
Start = new DateTime(2000, 7, 1),
|
||||||
End = new DateTime(2000, 8, 30),
|
End = new DateTime(2000, 8, 30),
|
||||||
State = DocumentState.Submitted,
|
State = DocumentState.Submitted,
|
||||||
@ -215,10 +212,7 @@ namespace InternshipSystem.Repository
|
|||||||
InternshipRegistration = new InternshipRegistration
|
InternshipRegistration = new InternshipRegistration
|
||||||
{
|
{
|
||||||
Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco
|
Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco
|
||||||
Type = new InternshipType
|
Type = InternshipType.UOZ,
|
||||||
{
|
|
||||||
Type = "UZ"
|
|
||||||
},
|
|
||||||
Start = new DateTime(2000, 7, 1),
|
Start = new DateTime(2000, 7, 1),
|
||||||
End = new DateTime(2000, 8, 30),
|
End = new DateTime(2000, 8, 30),
|
||||||
State = DocumentState.Submitted,
|
State = DocumentState.Submitted,
|
||||||
|
Loading…
Reference in New Issue
Block a user