template controller
This commit is contained in:
@@ -10,6 +10,7 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class EsppDataController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<EsppDataController> logger;
|
||||
private readonly IFileService fileService;
|
||||
private readonly StorageSettings storageSettings;
|
||||
|
||||
@@ -19,36 +20,36 @@ namespace PARR.API.Controllers.V1
|
||||
StorageSettings storageSettings
|
||||
)
|
||||
{
|
||||
Logger = logger;
|
||||
this.logger = logger;
|
||||
this.fileService = fileService;
|
||||
this.storageSettings = storageSettings;
|
||||
}
|
||||
|
||||
public ILogger<EsppDataController> Logger { get; }
|
||||
// UploadTemplates - неактуально, так как стали брать данные с RabbitMQ
|
||||
|
||||
/// <summary>
|
||||
/// Загрузить файл списка шаблонов полученных из ЕСПП в формате csv
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
{
|
||||
if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions))
|
||||
return BadRequest(
|
||||
new Response(false,
|
||||
new List<ErrorModel> {
|
||||
new ErrorModel {
|
||||
Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}"
|
||||
} }));
|
||||
///// <summary>
|
||||
///// Загрузить файл списка шаблонов полученных из ЕСПП в формате csv
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
//public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
//{
|
||||
// if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions))
|
||||
// return BadRequest(
|
||||
// new Response(false,
|
||||
// new List<ErrorModel> {
|
||||
// new ErrorModel {
|
||||
// Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}"
|
||||
// } }));
|
||||
|
||||
if (!fileService.IsNotExceededLimit(file, storageSettings.EsppTemplates.MaxFileSizeMb))
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(file), Message = $"Размер файла превышает {storageSettings.EsppTemplates.MaxFileSizeMb} МБайт" } }));
|
||||
// if (!fileService.IsNotExceededLimit(file, storageSettings.EsppTemplates.MaxFileSizeMb))
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(file), Message = $"Размер файла превышает {storageSettings.EsppTemplates.MaxFileSizeMb} МБайт" } }));
|
||||
|
||||
var uploadResult = await fileService.UploadAsync(file, storageSettings.EsppTemplates.TemplatePath);
|
||||
if (uploadResult == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при сохранении файла" } }));
|
||||
// var uploadResult = await fileService.UploadAsync(file, storageSettings.EsppTemplates.TemplatePath);
|
||||
// if (uploadResult == null)
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при сохранении файла" } }));
|
||||
|
||||
return Ok(new Response<string>("", true, new List<ErrorModel>(), $"Файл загружен."));
|
||||
}
|
||||
// return Ok(new Response<string>("", true, new List<ErrorModel>(), $"Файл загружен."));
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models.V1;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.V1;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
|
||||
42
PARR.API/Controllers/V1/StatusTemplateController.cs
Normal file
42
PARR.API/Controllers/V1/StatusTemplateController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using AutoMapper;
|
||||
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.DAL.Services;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class StatusTemplateController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IStatusTemplateService statusTemplateService;
|
||||
|
||||
public StatusTemplateController(
|
||||
IMapper mapper,
|
||||
IStatusTemplateService statusTemplateService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.statusTemplateService = statusTemplateService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список статусов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatusTemplate.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var statusList = await statusTemplateService.Get()
|
||||
.OrderBy(t => t.Code)
|
||||
.ToListAsync();
|
||||
|
||||
var response = mapper.Map<List<StatusTemplateResponse>>(statusList);
|
||||
|
||||
return Ok(new Response<List<StatusTemplateResponse>>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
136
PARR.API/Controllers/V1/TemplateController.cs
Normal file
136
PARR.API/Controllers/V1/TemplateController.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class TemplateController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly ITemplateService templateService;
|
||||
|
||||
public TemplateController(
|
||||
IMapper mapper,
|
||||
ITemplateService templateService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.templateService = templateService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список всех шаблонов постранично
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Template.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] TemplateQuery filter)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<Template> query = templateService.Get()
|
||||
.OrderBy(t => t.Name);
|
||||
|
||||
if (filter.StatusCode.HasValue)
|
||||
{
|
||||
switch (filter.StatusCode.Value)
|
||||
{
|
||||
case (int)StatusTemplateEnum.Ok:
|
||||
query = query.Where(t => t.StatusCode == (int)StatusTemplateEnum.Ok);
|
||||
break;
|
||||
case (int)StatusTemplateEnum.Creating:
|
||||
query = query.Where(t => t.StatusCode == (int)StatusTemplateEnum.Creating);
|
||||
break;
|
||||
case (int)StatusTemplateEnum.Updating:
|
||||
query = query.Where(t => t.StatusCode == (int)StatusTemplateEnum.Updating);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var templates = await templateService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!templates.Any())
|
||||
return NoContent();
|
||||
|
||||
var templateResponse = mapper.Map<List<TemplateResponse>>(templates);
|
||||
var paginationResponse = new PagedResponse<TemplateResponse>(templateResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить шаблон по id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Template.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
{
|
||||
var template = await templateService.GetAsync(id);
|
||||
|
||||
if (template == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить один шаблон по заданному статусу
|
||||
/// </summary>
|
||||
/// <param name="statusCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Template.GetByStatusCode)]
|
||||
public async Task<IActionResult> GetByStatus([FromRoute] int statusCode)
|
||||
{
|
||||
var template = await templateService.Get().FirstOrDefaultAsync(t => t.StatusCode == statusCode);
|
||||
|
||||
if (template == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Установить статус ОК для шаблона с id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut(ApiRoutes.Template.SetOkStatus)]
|
||||
public async Task<IActionResult> SetOkStatus([FromRoute] Guid id)
|
||||
{
|
||||
var template = await templateService.GetAsync(id);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {id}" } }));
|
||||
|
||||
template.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении статуса у шаблона с id: {id}" } }));
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user