feat(api): создан SubprocessController+валидация входных данных

This commit is contained in:
Mikhail Kuznetsov
2024-03-06 15:09:48 +10:00
parent 563f56b770
commit 9f3b470854
4 changed files with 258 additions and 8 deletions

View File

@@ -1,21 +1,20 @@
using AutoMapper;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Requests;
using PARR.API.Contracts.V1.Requests.Queries;
using PARR.API.Contracts.V1.Responses.Base;
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.API.Services.Interfaces;
using PARR.Constants;
using PARR.DAL.DomainModels;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Models;
using Microsoft.EntityFrameworkCore;
using PARR.API.Extensions;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
@@ -74,7 +73,7 @@ namespace PARR.API.Controllers.V1
if (!await tnkService.CreateAsync(tnk) || !await tnkService.CommitAsync())
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при записи новой ТНК в базу данных" } }));
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил вид работ: {tnk.Name}, {tnk.EsppId}, {tnk.SubprocessId}");
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил ТНК: {tnk.Name}, {tnk.EsppId}, {tnk.SubprocessId}");
var locationUri = uriService.GetUri(ApiRoutes.Tnk.Get, ApiRoutes.Tnk.getParam, tnk.Id);
@@ -93,7 +92,6 @@ namespace PARR.API.Controllers.V1
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
IQueryable<Tnk> query = tnkService.Get()
//.Include(t=>t.Subprocess).ThenInclude(t=>t.Process)
.OrderBy(t => t.Name);
var tnks = await tnkService.GetPage(query, paginationFilter).ToListAsync();
@@ -143,7 +141,7 @@ namespace PARR.API.Controllers.V1
if (tnk == null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найдена ТНК с id: {id}" } }));
var response = mapper.Map<List<WorkResponse>>(tnk.Works.OrderBy(t=>t.Name).ToList());//Roles.Select(t => t.Role)).OrderBy(t => t.Description).ToList();
var response = mapper.Map<List<WorkResponse>>(tnk.Works.OrderBy(t => t.Name).ToList());
return Ok(new Response<List<WorkResponse>>(response, true));
}