Rewrite InternshipType

This commit is contained in:
mborzyszkowski 2020-09-12 16:03:05 +02:00
parent a508f9f4a8
commit a06991a318
10 changed files with 141 additions and 78 deletions

View File

@ -20,6 +20,7 @@ namespace InternshipSystem.Api.Controllers
public async Task<IActionResult> Fill()
{
await FillerService.FillCompanies();
await FillerService.FillInternshipTypes();
await FillerService.FillEditions();
await FillerService.FillStaticPages();
return Ok();
@ -31,6 +32,13 @@ namespace InternshipSystem.Api.Controllers
await FillerService.FillCompanies();
return Ok();
}
[HttpPost("fill/internshipTypes")]
public async Task<IActionResult> FillInternshipTypesAsync()
{
await FillerService.FillInternshipTypes();
return Ok();
}
[HttpPost("fill/editions")]
public async Task<IActionResult> FillEditionsAsync()

View File

@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using InternshipSystem.Api.Security;
using InternshipSystem.Core.Entity.Internship;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace InternshipSystem.Api.Controllers
{
[ApiController]
[Route("internshipType")]
public class InternshipTypesController : ControllerBase
{
public InternshipTypesController(InternshipDbContext context)
{
Context = context;
}
private InternshipDbContext Context { get; }
/// <summary>
/// Get all internship types
/// </summary>
/// <returns>List of internship types</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IList<InternshipType>>> GetAllInternshipTypes(CancellationToken cancellationToken) =>
await Context.InternshipTypes
.ToListAsync(cancellationToken);
/// <summary>
/// Get static page
/// </summary>
/// <returns>List of internship types for edition</returns>
[HttpGet("forCurrentEdition")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Authorize]
public async Task<ActionResult<IList<InternshipType>>> GetInternshipTypesForEdition([FromServices] User user, CancellationToken cancellationToken)
{
var edition =
await Context.Editions
.Include(e => e.AvailableInternshipTypes)
.Where(e => e.Id.Equals(user.EditionId))
.FirstOrDefaultAsync(cancellationToken: cancellationToken);
if (edition == null)
{
return NotFound();
}
return Ok(edition.AvailableInternshipTypes);
}
}
}

View File

@ -10,7 +10,7 @@ namespace InternshipSystem.Api.Queries
public BranchOfficeForm BranchOffice { get; set; }
public DateTime? Start { get; set; }
public DateTime? End { get; set; }
public InternshipType? Type { get; set; }
public InternshipType Type { get; set; }
public class Validator : AbstractValidator<RegistrationFormQuery>
{

View File

@ -68,7 +68,7 @@ namespace InternshipSystem.Api.Services
internshipRegistration.Start = registrationQuery.Start ?? internshipRegistration.Start;
internshipRegistration.End = registrationQuery.End ?? internshipRegistration.End;
if (registrationQuery.Type.HasValue && edition.IsInternshipTypeAllowed(registrationQuery.Type.Value))
if (registrationQuery.Type != null && edition.IsInternshipTypeAllowed(registrationQuery.Type))
{
return new BadRequestObjectResult("Edition doesn't have this type of employment in available employments type");
}

View File

@ -15,7 +15,7 @@ namespace InternshipSystem.Core
public Course Course { get; set; }
public List<Internship> Internships { get; set; }
public List<EditionSubject> AvailableSubjects { get; set; }
public List<EditionInternshipType> AvailableInternshipTypes { get; set; }
public List<InternshipType> AvailableInternshipTypes { get; set; }
public bool IsOpen => EditionFinish < DateTime.Today;
@ -31,7 +31,7 @@ namespace InternshipSystem.Core
public bool IsInternshipTypeAllowed(InternshipType registrationQueryType)
{
return AvailableInternshipTypes.Select(it => it.InternshipType).Contains(registrationQueryType);
return AvailableInternshipTypes.Contains(registrationQueryType);
}
public void RegisterInternship(Student student)

View File

@ -1,14 +1,9 @@
namespace InternshipSystem.Core.Entity.Internship
{
public enum InternshipType
{
FreeInternship = 0,
GraduateInternship = 1,
FreeApprenticeship = 2,
PaidApprenticeship = 3,
ForeignInternship = 4,
UOP = 5,
UD = 6,
UZ = 7,
public class InternshipType
{
public long Id { get; set; }
public string Type { get; set; }
public string Description { get; set; }
}
}

View File

@ -2,7 +2,7 @@
{
public class StaticPage
{
public long? Id { get; set; }
public long Id { get; set; }
public string AccessName { get; set; }
public string Title { get; set; }
public string Content { get; set; }

View File

@ -1,11 +0,0 @@
using System;
using InternshipSystem.Core.Entity.Internship;
namespace InternshipSystem.Core.UglyOrmArtifacts
{
public class EditionInternshipType
{
public long Id { get; set; }
public InternshipType InternshipType { get; set; }
}
}

View File

@ -102,12 +102,62 @@ namespace InternshipSystem.Repository
await Context.SaveChangesAsync();
}
public async Task FillInternshipTypes()
{
var internshipTypes = new List<InternshipType>
{
new InternshipType
{
Type = "FreeInternship",
Description = "Praktyka bezpłatna",
},
new InternshipType
{
Type = "GraduateInternship",
Description = "Praktyka absolwencka",
},
new InternshipType
{
Type = "FreeApprenticeship",
Description = "Praktyka bezpłatna",
},
new InternshipType
{
Type = "PaidApprenticeship",
Description = "np. przemysłowy",
},
new InternshipType
{
Type = "ForeignInternship",
Description = "np. IAESTE, ERASMUS",
},
new InternshipType
{
Type = "UOP",
Description = "umowa o pracę",
},
new InternshipType
{
Type = "UD",
Description = "umowa o dzieło",
},
new InternshipType
{
Type = "UZ",
Description = "umowa zlecenie",
},
};
await Context.InternshipTypes.AddRangeAsync(internshipTypes);
await Context.SaveChangesAsync();
}
public async Task FillEditions()
{
var editions = new List<Edition>
{
new Edition
{
Id = Guid.Parse("138da8a3-855c-4b17-9bd2-5f357679efa9"),
EditionStart = new DateTime(2000, 5, 10),
EditionFinish = new DateTime(2000, 11, 10),
ReportingStart = new DateTime(2000, 9, 30),
@ -139,12 +189,12 @@ namespace InternshipSystem.Repository
{
Name = "Informatyka",
},
AvailableInternshipTypes = new List<EditionInternshipType>
AvailableInternshipTypes = new List<InternshipType>
{
new EditionInternshipType() { InternshipType = InternshipType.UOP },
new EditionInternshipType() { InternshipType = InternshipType.UZ },
new EditionInternshipType() { InternshipType = InternshipType.UD },
new EditionInternshipType() { InternshipType = InternshipType.FreeInternship },
Context.InternshipTypes.First(t => t.Type.Equals("UOP")),
Context.InternshipTypes.First(t => t.Type.Equals("UZ")),
Context.InternshipTypes.First(t => t.Type.Equals("UD")),
Context.InternshipTypes.First(t => t.Type.Equals("FreeInternship")),
},
Internships = new List<Internship>(),
}
@ -166,15 +216,15 @@ namespace InternshipSystem.Repository
},
InternshipRegistration = new InternshipRegistration
{
Company = Context.Companies.First(c => c.Id.Equals(1)), //Intel
Type = InternshipType.UOP,
Company = Context.Companies.First(c => c.Name.Equals("Intel")),
Type = Context.InternshipTypes.First(t => t.Type.Equals("UOP")),
Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted,
BranchAddress =
Context.Companies
.Include(c => c.Branches)
.First(c => c.Id.Equals(1))
.First(c => c.Name.Equals("Intel"))
.Branches
.First(),
},
@ -216,15 +266,15 @@ namespace InternshipSystem.Repository
},
InternshipRegistration = new InternshipRegistration
{
Company = Context.Companies.First(c => c.Id.Equals(2)), //Asseco
Type = InternshipType.UZ,
Company = Context.Companies.First(c => c.Name.Equals("Asseco Poland")),
Type = Context.InternshipTypes.First(t => t.Type.Equals("UZ")),
Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted,
BranchAddress =
Context.Companies
.Include(c => c.Branches)
.First(c => c.Id.Equals(2))
.First(c => c.Name.Equals("Asseco Poland"))
.Branches
.First(),
},
@ -278,46 +328,5 @@ namespace InternshipSystem.Repository
await Context.StaticPages.AddRangeAsync(staticPages);
await Context.SaveChangesAsync();
}
// new InternshipType
// {
// Type = "FreeInternship",
// Description = "Praktyka bezpłatna",
// },
// new InternshipType
// {
// Type = "GraduateInternship"
// },
// new InternshipType
// {
// Type = "FreeApprenticeship"
// },
// new InternshipType
// {
// Type = "PaidApprenticeship",
// Description = "np. przemysłowy"
// },
// new InternshipType
// {
// Type = "ForeignInternship",
// Description = "np. IAESTE, ERASMUS"
// },
// new InternshipType
// {
// Type = "UOP"
// },
// new InternshipType
// {
// Type = "UD"
// },
// new InternshipType
// {
// Type = "UZ"
// },
// new InternshipType
// {
// Type = "Other",
// Description = "Należy wprowadzić samodzielnie"
// }
}
}

View File

@ -10,6 +10,7 @@ namespace InternshipSystem.Repository
public DbSet<Company> Companies { get; set; }
public DbSet<Edition> Editions { get; set; }
public DbSet<StaticPage> StaticPages { get; set; }
public DbSet<InternshipType> InternshipTypes { get; set; }
public DbSet<Student> Students { get; set; }
public InternshipDbContext(DbContextOptions<InternshipDbContext> options)