feat(api, dal): EsppScheduleTypeScheduleController. В таблицу EsppScheTypeValue добавлено поле Order
This commit is contained in:
@@ -313,6 +313,18 @@
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
#region Расписание ЕСПП
|
||||
|
||||
public static class EsppScheduleTypeSchedule
|
||||
{
|
||||
public const string GetAll = Base + "/espp-schedule-type-schedules/";
|
||||
public const string Get = Base + "/espp-schedule-type-schedules/" + getParam;
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
public required string Description { get; set; }
|
||||
}
|
||||
|
||||
public class EsppScheduleTypeScheduleWithDataResponse : EsppScheduleTypeScheduleResponse
|
||||
{
|
||||
public List<EsppScheduleTypeConfigWithDataResponse>? Configs { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class EsppScheduleTypeResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
@@ -41,6 +47,11 @@
|
||||
public required string Description { get; set; }
|
||||
}
|
||||
|
||||
public class EsppScheduleTypeWithDataResponse : EsppScheduleTypeResponse
|
||||
{
|
||||
public List<EsppScheduleTypeValueResponse>? Values { get; set; }
|
||||
}
|
||||
|
||||
public class EsppScheduleTypeValueResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
@@ -48,4 +59,13 @@
|
||||
public required string Value { get; set; }
|
||||
}
|
||||
|
||||
public class EsppScheduleTypeConfigWithDataResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public EsppScheduleTypeWithDataResponse? Type { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Типы заданий из расписания ЕСПП (Регулярно, Еженедельно, Ежемесячно...)
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class EsppScheduleTypeScheduleController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IEsppSchTypeScheduleService esppSchTypeScheduleService;
|
||||
|
||||
public EsppScheduleTypeScheduleController(
|
||||
IMapper mapper,
|
||||
IEsppSchTypeScheduleService esppSchTypeScheduleService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.esppSchTypeScheduleService = esppSchTypeScheduleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Список типов заданий расписания ЕСПП
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.EsppScheduleTypeSchedule.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var objs = await esppSchTypeScheduleService.Get()
|
||||
.OrderBy(t => t.Id)
|
||||
.ToListAsync();
|
||||
|
||||
if (!objs.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<EsppScheduleTypeScheduleResponse>>(objs);
|
||||
|
||||
return Ok(new Response<List<EsppScheduleTypeScheduleResponse>>(response, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Тип задания из расписания ЕСПП по ИД, с вложенной структурой
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.EsppScheduleTypeSchedule.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] int id)
|
||||
{
|
||||
var obj = await esppSchTypeScheduleService.Get()
|
||||
.Include(t => t.EsppSchTypeConfigs)
|
||||
.ThenInclude(t => t.EsppSchType)
|
||||
.ThenInclude(t => t.EsppSchTypeValues)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (obj == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<EsppScheduleTypeScheduleWithDataResponse>(obj);
|
||||
|
||||
return Ok(new Response<EsppScheduleTypeScheduleWithDataResponse>(response, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -181,9 +181,23 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
|
||||
#region EsppSch
|
||||
CreateMap<EsppSchTypeSchedule, EsppScheduleTypeScheduleResponse>();
|
||||
CreateMap<EsppSchTypeSchedule, EsppScheduleTypeScheduleResponse>()
|
||||
.Include<EsppSchTypeSchedule, EsppScheduleTypeScheduleWithDataResponse>();
|
||||
|
||||
CreateMap<EsppSchTypeSchedule, EsppScheduleTypeScheduleWithDataResponse>()
|
||||
.ForMember(d => d.Configs, o => o.MapFrom(s => s.EsppSchTypeConfigs.OrderBy(t => t.Order)));
|
||||
|
||||
|
||||
CreateMap<EsppSchTypeConfig, EsppScheduleTypeConfigWithDataResponse>()
|
||||
.ForMember(d => d.Type, o => o.MapFrom(s => s.EsppSchType));
|
||||
|
||||
|
||||
CreateMap<EsppSchType, EsppScheduleTypeResponse>()
|
||||
.Include<EsppSchType, EsppScheduleTypeWithDataResponse>();
|
||||
|
||||
CreateMap<EsppSchType, EsppScheduleTypeWithDataResponse>()
|
||||
.ForMember(d => d.Values, o => o.MapFrom(s => s.EsppSchTypeValues.OrderBy(t => t.Order)));
|
||||
|
||||
CreateMap<EsppSchType, EsppScheduleTypeResponse>();
|
||||
|
||||
CreateMap<EsppSchTypeValue, EsppScheduleTypeValueResponse>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user