fix
This commit is contained in:
parent
2178cde4dd
commit
4bdc04858e
@ -21,6 +21,8 @@ namespace InternshipSystem.Api
|
||||
|
||||
CreateMap<Edition, EditionManagementResult>();
|
||||
|
||||
CreateMap<Edition, EditionReportSchemaResult>();
|
||||
|
||||
CreateMap<Edition, EditionDetailsResult>();
|
||||
|
||||
CreateMap<Edition, EditionConfigurationResult>();
|
||||
|
@ -99,6 +99,8 @@ namespace InternshipSystem.Api.Controllers
|
||||
var edition =
|
||||
await Context.Editions
|
||||
.Include(e => e.AvailableSubjects)
|
||||
.Include(e => e.ReportSchema)
|
||||
.ThenInclude(e => e.Field)
|
||||
.Include(e => e.Course)
|
||||
.Where(e => e.Id == user.EditionId)
|
||||
.ProjectTo<EditionConfigurationResult>(Mapper.ConfigurationProvider)
|
||||
|
@ -43,6 +43,8 @@ namespace InternshipSystem.Api.Controllers
|
||||
.Skip(searchQuery.Page * searchQuery.PerPage)
|
||||
.Take(searchQuery.PerPage)
|
||||
.ToListAsync(token);
|
||||
|
||||
|
||||
|
||||
[HttpGet("{editionId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
@ -57,6 +59,8 @@ namespace InternshipSystem.Api.Controllers
|
||||
.ThenInclude(s => s.Subject)
|
||||
.Include(e => e.AvailableInternshipTypes)
|
||||
.ThenInclude(i => i.InternshipType)
|
||||
.Include(e => e.ReportSchema)
|
||||
.ThenInclude(er => er.Field)
|
||||
.Where(e => e.Id == editionId)
|
||||
.ProjectTo<EditionDetailsResult>(Mapper.ConfigurationProvider)
|
||||
.FirstOrDefaultAsync(token);
|
||||
@ -68,7 +72,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
|
||||
return Ok(edition);
|
||||
}
|
||||
|
||||
|
||||
[HttpPut]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
@ -90,6 +94,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
var editionToUpdate = await Context.Editions
|
||||
.Include(e => e.AvailableSubjects)
|
||||
.Include(e => e.AvailableInternshipTypes)
|
||||
.Include(e => e.ReportSchema)
|
||||
.FirstOrDefaultAsync(e => e.Id == editionForm.Id.Value, token);
|
||||
|
||||
if (editionToUpdate == null)
|
||||
@ -98,7 +103,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -109,7 +114,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
{
|
||||
var newEdition =
|
||||
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)
|
||||
{
|
||||
@ -135,6 +140,7 @@ namespace InternshipSystem.Api.Controllers
|
||||
var editionToDelete = await Context.Editions
|
||||
.Include(e => e.AvailableSubjects)
|
||||
.Include(e => e.AvailableInternshipTypes)
|
||||
.Include(e => e.ReportSchema)
|
||||
.FirstOrDefaultAsync(e => e.Id.Equals(editionId), token);
|
||||
|
||||
if (editionToDelete == null)
|
||||
|
@ -1,64 +1,89 @@
|
||||
// using System;
|
||||
// using System.Threading;
|
||||
// using System.Threading.Tasks;
|
||||
// using AutoMapper;
|
||||
// using InternshipSystem.Core;
|
||||
// using InternshipSystem.Core.Entity;
|
||||
// using InternshipSystem.Repository;
|
||||
// using Microsoft.AspNetCore.Mvc;
|
||||
//
|
||||
// namespace InternshipSystem.Api.Controllers
|
||||
// {
|
||||
// public class ReportFieldsController : ControllerBase
|
||||
// {
|
||||
// private readonly InternshipDbContext _context;
|
||||
// private readonly IMapper _mapper;
|
||||
//
|
||||
// public ReportFieldsController(InternshipDbContext context, IMapper mapper)
|
||||
// {
|
||||
// _context = context;
|
||||
// _mapper = mapper;
|
||||
// }
|
||||
//
|
||||
// public async Task<ActionResult> CreateField(FieldCreateRequest request, CancellationToken ct)
|
||||
// {
|
||||
// ReportField field;
|
||||
//
|
||||
// switch (request.FieldType)
|
||||
// {
|
||||
// case FieldType.LongText:
|
||||
// case FieldType.ShortText:
|
||||
// field = new ReportField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType);
|
||||
// break;
|
||||
// case FieldType.Select:
|
||||
// case FieldType.Radial:
|
||||
// case FieldType.Checkbox:
|
||||
// field = new ReportChoiceField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType, request.Choices);
|
||||
// break;
|
||||
// default:
|
||||
// return BadRequest("Unknown field type");
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// await _context.ReportFields.AddAsync(field, ct);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// return BadRequest("Failed");
|
||||
// }
|
||||
//
|
||||
// return Ok();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// 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; }
|
||||
// }
|
||||
// }
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using InternshipSystem.Api.Queries.SearchQuery;
|
||||
using InternshipSystem.Api.Security;
|
||||
using InternshipSystem.Core;
|
||||
using InternshipSystem.Core.Entity;
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InternshipSystem.Api.Controllers
|
||||
{
|
||||
[Route("management/report")]
|
||||
public class ReportFieldsController : ControllerBase
|
||||
{
|
||||
private readonly InternshipDbContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ReportFieldsController(InternshipDbContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("fields")]
|
||||
[Authorize(Policy = Policies.IsOverseer)]
|
||||
public async Task<IEnumerable<ReportField>> GetFields(FieldSearchQuery searchQuery, CancellationToken ct) =>
|
||||
await _context.ReportFields
|
||||
.Where(c => c.Label.ToLower().Contains(searchQuery.Label.ToLower()))
|
||||
.OrderBy(o => o.Label)
|
||||
.Skip(searchQuery.Page * searchQuery.PerPage)
|
||||
.Take(searchQuery.PerPage)
|
||||
.ToListAsync(ct);
|
||||
|
||||
[HttpPost("fields")]
|
||||
[Authorize(Policy = Policies.IsOverseer)]
|
||||
public async Task<ActionResult> CreateField([FromBody] FieldCreateRequest request, CancellationToken ct)
|
||||
{
|
||||
ReportField field;
|
||||
|
||||
switch (request.FieldType)
|
||||
{
|
||||
case FieldType.LongText:
|
||||
case FieldType.ShortText:
|
||||
field = new ReportField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType);
|
||||
break;
|
||||
case FieldType.Select:
|
||||
case FieldType.Radial:
|
||||
case FieldType.Checkbox:
|
||||
field = new ReportChoiceField(request.Label, request.LabelEng, request.Description, request.DescriptionEng, request.FieldType, request.Choices);
|
||||
break;
|
||||
default:
|
||||
return BadRequest("Unknown field type");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ namespace InternshipSystem.Api.Queries
|
||||
public Course Course { get; set; }
|
||||
public List<long> AvailableSubjectsIds { 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>
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ namespace InternshipSystem.Api.Result
|
||||
public class EditionConfigurationResult
|
||||
{
|
||||
public List<InternshipSubject> AvailableSubjects { get; set; }
|
||||
public List<ReportField> ReportSchema { get; set; }
|
||||
public Course Course { get; set; }
|
||||
public DateTime EditionStart { get; set; }
|
||||
public DateTime EditionFinish { get; set; }
|
||||
|
@ -15,5 +15,6 @@ namespace InternshipSystem.Api.Result
|
||||
public Course Course { get; set; }
|
||||
public List<InternshipSubject> AvailableSubjects { get; set; }
|
||||
public List<InternshipType> AvailableInternshipTypes { get; set; }
|
||||
public List<ReportField> ReportSchema { get; set; }
|
||||
}
|
||||
}
|
@ -5,6 +5,6 @@ namespace InternshipSystem.Api.Result
|
||||
{
|
||||
public class EditionReportSchemaResult
|
||||
{
|
||||
public List<ReportField> Fields { get; set; }
|
||||
public List<ReportField> ReportSchema { get; set; }
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ namespace InternshipSystem.Core
|
||||
public bool IsOpen => EditionFinish < DateTime.Today;
|
||||
|
||||
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);
|
||||
|
||||
@ -43,6 +43,15 @@ namespace InternshipSystem.Core
|
||||
InternshipTypeId = i,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
newEdition.ReportSchema =
|
||||
reportFieldIds
|
||||
.Select(i => new ReportFieldEdition
|
||||
{
|
||||
Edition = newEdition,
|
||||
ReportFieldId = i,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return newEdition;
|
||||
}
|
||||
@ -57,11 +66,12 @@ namespace InternshipSystem.Core
|
||||
Course = course,
|
||||
AvailableSubjects = new List<EditionSubject>(),
|
||||
AvailableInternshipTypes = new List<EditionInternshipType>(),
|
||||
ReportSchema = new List<ReportFieldEdition>()
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
EditionFinish = end ?? EditionFinish;
|
||||
@ -89,6 +99,17 @@ namespace InternshipSystem.Core
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (reportFieldIds != null)
|
||||
{
|
||||
ReportSchema =
|
||||
reportFieldIds
|
||||
.Select(i => new ReportFieldEdition
|
||||
{
|
||||
ReportFieldId = i,
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterInternship(Student student)
|
||||
|
@ -7,7 +7,7 @@ namespace InternshipSystem.Core.UglyOrmArtifacts
|
||||
{
|
||||
public Guid EditionId { get; set; }
|
||||
public Edition Edition { get; set; }
|
||||
public int ReportFieldId { get; set; }
|
||||
public long ReportFieldId { get; set; }
|
||||
public ReportField Field { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user