5fbbd08e3c3b321c1d203b13 #89

Open
maxchil wants to merge 8 commits from 5fbbd08e3c3b321c1d203b13 into master
10 changed files with 130 additions and 71 deletions
Showing only changes of commit 4bdc04858e - Show all commits

View File

@ -21,6 +21,8 @@ namespace InternshipSystem.Api
CreateMap<Edition, EditionManagementResult>(); CreateMap<Edition, EditionManagementResult>();
CreateMap<Edition, EditionReportSchemaResult>();
CreateMap<Edition, EditionDetailsResult>(); CreateMap<Edition, EditionDetailsResult>();
CreateMap<Edition, EditionConfigurationResult>(); CreateMap<Edition, EditionConfigurationResult>();

View File

@ -99,6 +99,8 @@ namespace InternshipSystem.Api.Controllers
var edition = var edition =
await Context.Editions await Context.Editions
.Include(e => e.AvailableSubjects) .Include(e => e.AvailableSubjects)
.Include(e => e.ReportSchema)
.ThenInclude(e => e.Field)
.Include(e => e.Course) .Include(e => e.Course)
.Where(e => e.Id == user.EditionId) .Where(e => e.Id == user.EditionId)
.ProjectTo<EditionConfigurationResult>(Mapper.ConfigurationProvider) .ProjectTo<EditionConfigurationResult>(Mapper.ConfigurationProvider)

View File

@ -44,6 +44,8 @@ namespace InternshipSystem.Api.Controllers
.Take(searchQuery.PerPage) .Take(searchQuery.PerPage)
.ToListAsync(token); .ToListAsync(token);
[HttpGet("{editionId}")] [HttpGet("{editionId}")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
@ -57,6 +59,8 @@ namespace InternshipSystem.Api.Controllers
.ThenInclude(s => s.Subject) .ThenInclude(s => s.Subject)
.Include(e => e.AvailableInternshipTypes) .Include(e => e.AvailableInternshipTypes)
.ThenInclude(i => i.InternshipType) .ThenInclude(i => i.InternshipType)
.Include(e => e.ReportSchema)
.ThenInclude(er => er.Field)
.Where(e => e.Id == editionId) .Where(e => e.Id == editionId)
.ProjectTo<EditionDetailsResult>(Mapper.ConfigurationProvider) .ProjectTo<EditionDetailsResult>(Mapper.ConfigurationProvider)
.FirstOrDefaultAsync(token); .FirstOrDefaultAsync(token);
@ -90,6 +94,7 @@ namespace InternshipSystem.Api.Controllers
var editionToUpdate = await Context.Editions var editionToUpdate = await Context.Editions
.Include(e => e.AvailableSubjects) .Include(e => e.AvailableSubjects)
.Include(e => e.AvailableInternshipTypes) .Include(e => e.AvailableInternshipTypes)
.Include(e => e.ReportSchema)
.FirstOrDefaultAsync(e => e.Id == editionForm.Id.Value, token); .FirstOrDefaultAsync(e => e.Id == editionForm.Id.Value, token);
if (editionToUpdate == null) if (editionToUpdate == null)
@ -98,7 +103,7 @@ namespace InternshipSystem.Api.Controllers
} }
editionToUpdate.UpdateEdition(editionForm.EditionStart, editionForm.EditionFinish, editionForm.ReportingStart, editionToUpdate.UpdateEdition(editionForm.EditionStart, editionForm.EditionFinish, editionForm.ReportingStart,
editionForm.Course, editionForm.AvailableSubjectsIds, editionForm.AvailableInternshipTypesIds); editionForm.Course, editionForm.AvailableSubjectsIds, editionForm.AvailableInternshipTypesIds, editionForm.ReportSchema);
if (!editionToUpdate.IsValidDates) if (!editionToUpdate.IsValidDates)
{ {
@ -109,7 +114,7 @@ namespace InternshipSystem.Api.Controllers
{ {
var newEdition = var newEdition =
Edition.CreateEdition(editionForm.EditionStart.Value, editionForm.EditionFinish.Value, editionForm.ReportingStart.Value, Edition.CreateEdition(editionForm.EditionStart.Value, editionForm.EditionFinish.Value, editionForm.ReportingStart.Value,
editionForm.Course, editionForm.AvailableSubjectsIds, editionForm.AvailableInternshipTypesIds); editionForm.Course, editionForm.AvailableSubjectsIds, editionForm.AvailableInternshipTypesIds, editionForm.ReportSchema);
if (!newEdition.IsValidDates) if (!newEdition.IsValidDates)
{ {
@ -135,6 +140,7 @@ namespace InternshipSystem.Api.Controllers
var editionToDelete = await Context.Editions var editionToDelete = await Context.Editions
.Include(e => e.AvailableSubjects) .Include(e => e.AvailableSubjects)
.Include(e => e.AvailableInternshipTypes) .Include(e => e.AvailableInternshipTypes)
.Include(e => e.ReportSchema)
.FirstOrDefaultAsync(e => e.Id.Equals(editionId), token); .FirstOrDefaultAsync(e => e.Id.Equals(editionId), token);
if (editionToDelete == null) if (editionToDelete == null)

View File

@ -1,64 +1,89 @@
// using System; using System;
// using System.Threading; using System.Collections.Generic;
// using System.Threading.Tasks; using System.Linq;
// using AutoMapper; using System.Threading;
// using InternshipSystem.Core; using System.Threading.Tasks;
// using InternshipSystem.Core.Entity; using AutoMapper;
// using InternshipSystem.Repository; using InternshipSystem.Api.Queries.SearchQuery;
// using Microsoft.AspNetCore.Mvc; using InternshipSystem.Api.Security;
// using InternshipSystem.Core;
// namespace InternshipSystem.Api.Controllers using InternshipSystem.Core.Entity;
// { using InternshipSystem.Repository;
// public class ReportFieldsController : ControllerBase using Microsoft.AspNetCore.Authorization;
// { using Microsoft.AspNetCore.Mvc;
// private readonly InternshipDbContext _context; using Microsoft.EntityFrameworkCore;
// private readonly IMapper _mapper;
// namespace InternshipSystem.Api.Controllers
// public ReportFieldsController(InternshipDbContext context, IMapper mapper) {
// { [Route("management/report")]
// _context = context; public class ReportFieldsController : ControllerBase
// _mapper = mapper; {
// } private readonly InternshipDbContext _context;
// private readonly IMapper _mapper;
// public async Task<ActionResult> CreateField(FieldCreateRequest request, CancellationToken ct)
// { public ReportFieldsController(InternshipDbContext context, IMapper mapper)
// ReportField field; {
// _context = context;
// switch (request.FieldType) _mapper = mapper;
// { }
// case FieldType.LongText:
// case FieldType.ShortText: [HttpGet("fields")]
// field = new ReportField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType); [Authorize(Policy = Policies.IsOverseer)]
// break; public async Task<IEnumerable<ReportField>> GetFields(FieldSearchQuery searchQuery, CancellationToken ct) =>
// case FieldType.Select: await _context.ReportFields
// case FieldType.Radial: .Where(c => c.Label.ToLower().Contains(searchQuery.Label.ToLower()))
// case FieldType.Checkbox: .OrderBy(o => o.Label)
// field = new ReportChoiceField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType, request.Choices); .Skip(searchQuery.Page * searchQuery.PerPage)
// break; .Take(searchQuery.PerPage)
// default: .ToListAsync(ct);
// return BadRequest("Unknown field type");
// } [HttpPost("fields")]
// [Authorize(Policy = Policies.IsOverseer)]
// try public async Task<ActionResult> CreateField([FromBody] FieldCreateRequest request, CancellationToken ct)
// { {
// await _context.ReportFields.AddAsync(field, ct); ReportField field;
// }
// catch (Exception e) switch (request.FieldType)
// { {
// return BadRequest("Failed"); case FieldType.LongText:
// } case FieldType.ShortText:
// field = new ReportField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType);
// return Ok(); break;
// } case FieldType.Select:
// } case FieldType.Radial:
// case FieldType.Checkbox:
// public class FieldCreateRequest field = new ReportChoiceField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType, request.Choices);
// { break;
// public string Label { get; set; } default:
// public string LabelEng { get; set; } return BadRequest("Unknown field type");
// public string Description { get; set; } }
// public string DescriptionEng { get; set; }
// public FieldType FieldType { get; set; } try
// public string[] Choices { get; set; } {
// } await _context.ReportFields.AddAsync(field, ct);
// } await _context.SaveChangesAsync(ct);
}
catch (Exception e)
{
return BadRequest("Failed");
}
return Ok();
}
}
public class FieldSearchQuery : SearchQuery
{
public string Label { get; set; } = "";
}
public class FieldCreateRequest
{
public string Label { get; set; }
public string LabelEng { get; set; }
public string Description { get; set; }
public string DescriptionEng { get; set; }
public FieldType FieldType { get; set; }
public string[] Choices { get; set; }
}
}

View File

@ -16,6 +16,7 @@ namespace InternshipSystem.Api.Queries
public Course Course { get; set; } public Course Course { get; set; }
public List<long> AvailableSubjectsIds { get; set; } = new List<long>(); public List<long> AvailableSubjectsIds { get; set; } = new List<long>();
public List<long> AvailableInternshipTypesIds { get; set; } = new List<long>(); public List<long> AvailableInternshipTypesIds { get; set; } = new List<long>();
public List<long> ReportSchema { get; set; } = new List<long>();
public class Validator : AbstractValidator<EditionForm> public class Validator : AbstractValidator<EditionForm>
{ {

View File

@ -10,6 +10,7 @@ namespace InternshipSystem.Api.Result
public class EditionConfigurationResult public class EditionConfigurationResult
{ {
public List<InternshipSubject> AvailableSubjects { get; set; } public List<InternshipSubject> AvailableSubjects { get; set; }
public List<ReportField> ReportSchema { get; set; }
public Course Course { get; set; } public Course Course { get; set; }
public DateTime EditionStart { get; set; } public DateTime EditionStart { get; set; }
public DateTime EditionFinish { get; set; } public DateTime EditionFinish { get; set; }

View File

@ -15,5 +15,6 @@ namespace InternshipSystem.Api.Result
public Course Course { get; set; } public Course Course { get; set; }
public List<InternshipSubject> AvailableSubjects { get; set; } public List<InternshipSubject> AvailableSubjects { get; set; }
public List<InternshipType> AvailableInternshipTypes { get; set; } public List<InternshipType> AvailableInternshipTypes { get; set; }
public List<ReportField> ReportSchema { get; set; }
} }
} }

View File

@ -5,6 +5,6 @@ namespace InternshipSystem.Api.Result
{ {
public class EditionReportSchemaResult public class EditionReportSchemaResult
{ {
public List<ReportField> Fields { get; set; } public List<ReportField> ReportSchema { get; set; }
} }
} }

View File

@ -22,7 +22,7 @@ namespace InternshipSystem.Core
public bool IsOpen => EditionFinish < DateTime.Today; public bool IsOpen => EditionFinish < DateTime.Today;
public static Edition CreateEdition(DateTime start, DateTime end, DateTime reportingStart, Course course, public static Edition CreateEdition(DateTime start, DateTime end, DateTime reportingStart, Course course,
IEnumerable<long> subjectsIds, IEnumerable<long> internshipTypesIds) IEnumerable<long> subjectsIds, IEnumerable<long> internshipTypesIds, IEnumerable<long> reportFieldIds)
{ {
var newEdition = CreateEdition(start, end, reportingStart, course); var newEdition = CreateEdition(start, end, reportingStart, course);
@ -44,6 +44,15 @@ namespace InternshipSystem.Core
}) })
.ToList(); .ToList();
newEdition.ReportSchema =
reportFieldIds
.Select(i => new ReportFieldEdition
{
Edition = newEdition,
ReportFieldId = i,
})
.ToList();
return newEdition; return newEdition;
} }
@ -57,11 +66,12 @@ namespace InternshipSystem.Core
Course = course, Course = course,
AvailableSubjects = new List<EditionSubject>(), AvailableSubjects = new List<EditionSubject>(),
AvailableInternshipTypes = new List<EditionInternshipType>(), AvailableInternshipTypes = new List<EditionInternshipType>(),
ReportSchema = new List<ReportFieldEdition>()
}; };
} }
public void UpdateEdition(DateTime? start, DateTime? end, DateTime? reportingStart, Course course, public void UpdateEdition(DateTime? start, DateTime? end, DateTime? reportingStart, Course course,
IEnumerable<long> subjectsIds, IEnumerable<long> internshipTypesIds) IEnumerable<long> subjectsIds, IEnumerable<long> internshipTypesIds, IEnumerable<long> reportFieldIds)
{ {
EditionStart = start ?? EditionStart; EditionStart = start ?? EditionStart;
EditionFinish = end ?? EditionFinish; EditionFinish = end ?? EditionFinish;
@ -89,6 +99,17 @@ namespace InternshipSystem.Core
}) })
.ToList(); .ToList();
} }
if (reportFieldIds != null)
{
ReportSchema =
reportFieldIds
.Select(i => new ReportFieldEdition
{
ReportFieldId = i,
})
.ToList();
}
} }
public void RegisterInternship(Student student) public void RegisterInternship(Student student)

View File

@ -7,7 +7,7 @@ namespace InternshipSystem.Core.UglyOrmArtifacts
{ {
public Guid EditionId { get; set; } public Guid EditionId { get; set; }
public Edition Edition { get; set; } public Edition Edition { get; set; }
public int ReportFieldId { get; set; } public long ReportFieldId { get; set; }
public ReportField Field { get; set; } public ReportField Field { get; set; }
} }
} }