dummy
This commit is contained in:
parent
4549d31b6e
commit
3bc4e1cd03
@ -88,6 +88,5 @@ namespace InternshipSystem.Api.Controllers
|
||||
|
||||
return Ok(edition);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,9 +2,13 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InternshipSystem.Api.Queries;
|
||||
using InternshipSystem.Api.Security;
|
||||
using InternshipSystem.Core.Commands;
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InternshipSystem.Api.Controllers
|
||||
{
|
||||
@ -21,7 +25,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
/// <summary>
|
||||
/// Validate and add filled internship registration form
|
||||
/// </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="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>
|
||||
@ -29,7 +33,21 @@ namespace InternshipSystem.Api.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> SubmitRegistrationForm([FromBody] RegistrationFormQuery registrationQuery, CancellationToken cancellationToken) =>
|
||||
throw new NotImplementedException();
|
||||
[Authorize(Policy = Policies.RegisteredOnly)]
|
||||
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);
|
||||
|
||||
edition.RegisterInternship(student);
|
||||
await _context.SaveChangesAsync();
|
||||
await _context.SaveChangesAsync(token);
|
||||
|
||||
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
|
||||
{
|
||||
@ -8,16 +8,13 @@ namespace InternshipSystem.Core
|
||||
public long Id { get; set; }
|
||||
public Nip Nip { get; set; }
|
||||
public string Name { get; set; }
|
||||
public RangeOfActivity Range { 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
|
||||
{
|
||||
Nip = nip,
|
||||
Range = range,
|
||||
Name = name
|
||||
};
|
||||
}
|
||||
@ -25,5 +22,9 @@ namespace InternshipSystem.Core
|
||||
public void AddBranchAddress(BranchAddress branch)
|
||||
{
|
||||
}
|
||||
|
||||
public static Company CreateCompany(UpdateCompany updateCompany)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ namespace InternshipSystem.Core
|
||||
public DateTime ReportingStart { get; set; }
|
||||
public Course Course { get; set; }
|
||||
public List<Internship> Internships { get; set; }
|
||||
|
||||
public InternshipType AllowedInternshipTypes { get; set; }
|
||||
|
||||
public List<EditionSubject> AvailableSubjects { get; set; }
|
||||
|
||||
public bool IsOpen => EditionFinish < DateTime.Today;
|
||||
@ -33,5 +36,15 @@ namespace InternshipSystem.Core
|
||||
|
||||
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 InternshipSystem.Core.Commands;
|
||||
using InternshipSystem.Core.ValueObject;
|
||||
|
||||
namespace InternshipSystem.Core
|
||||
@ -13,6 +15,9 @@ namespace InternshipSystem.Core
|
||||
public Report Report { get; set; }
|
||||
public List<Document> Approvals { get; set; }
|
||||
public List<Document> Documentation { get; set; }
|
||||
|
||||
public Edition Edition { get; set; }
|
||||
|
||||
public float? Grade { get; set; }
|
||||
|
||||
public void UpdateDocument(Document document)
|
||||
@ -46,5 +51,38 @@ namespace InternshipSystem.Core
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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; }
|
||||
public string Type { get; set; }
|
||||
public string Description { get; set; }
|
||||
None,
|
||||
UOP,
|
||||
UOZ
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
namespace InternshipSystem.Core
|
||||
using System;
|
||||
|
||||
namespace InternshipSystem.Core
|
||||
{
|
||||
public class Report
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public DocumentState State { get; set; }
|
||||
public RangeOfActivity Range { get; set; }
|
||||
public Uri SiteAddress { get; set; }
|
||||
|
||||
public static Report Create()
|
||||
{
|
||||
|
@ -162,10 +162,7 @@ namespace InternshipSystem.Repository
|
||||
InternshipRegistration = new InternshipRegistration
|
||||
{
|
||||
Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel
|
||||
Type = new InternshipType
|
||||
{
|
||||
Type = "UOP"
|
||||
},
|
||||
Type = InternshipType.UOP,
|
||||
Start = new DateTime(2000, 7, 1),
|
||||
End = new DateTime(2000, 8, 30),
|
||||
State = DocumentState.Submitted,
|
||||
@ -215,10 +212,7 @@ namespace InternshipSystem.Repository
|
||||
InternshipRegistration = new InternshipRegistration
|
||||
{
|
||||
Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco
|
||||
Type = new InternshipType
|
||||
{
|
||||
Type = "UZ"
|
||||
},
|
||||
Type = InternshipType.UOZ,
|
||||
Start = new DateTime(2000, 7, 1),
|
||||
End = new DateTime(2000, 8, 30),
|
||||
State = DocumentState.Submitted,
|
||||
|
Loading…
Reference in New Issue
Block a user