| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using SVETA.Api.Data.DTO; |
| | | 3 | | using SVETA.Api.Data.DTO.Cluster; |
| | | 4 | | using Microsoft.AspNetCore.Mvc; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | using Newtonsoft.Json; |
| | | 7 | | using SVETA.Api.Data.DTO; |
| | | 8 | | using SVETA.Api.Data.DTO.DepartmentDTO; |
| | | 9 | | using SVETA.Api.Helpers.Authorize; |
| | | 10 | | using Swashbuckle.AspNetCore.Annotations; |
| | | 11 | | using System; |
| | | 12 | | using System.Collections.Generic; |
| | | 13 | | using System.Linq; |
| | | 14 | | using System.Threading.Tasks; |
| | | 15 | | using WinSolutions.Sveta.Common; |
| | | 16 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 17 | | using WinSolutions.Sveta.Server.Data.DataModel.Kinds; |
| | | 18 | | using WinSolutions.Sveta.Server.Domain; |
| | | 19 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 20 | | using SVETA.Api.Services.Interfaces; |
| | | 21 | | using AutoMapper; |
| | | 22 | | using SVETA.Api.Data.DTO.Movements; |
| | | 23 | | |
| | | 24 | | namespace SVETA.Api.Controllers |
| | | 25 | | { |
| | | 26 | | [Route("api/v1/MovementStatusRoutes")] |
| | | 27 | | [ApiController] |
| | | 28 | | [Authorize] |
| | | 29 | | public class MovementStatusRouteController : SvetaController |
| | | 30 | | { |
| | | 31 | | const string _routeUrl = "api/v1/MovementStatusRoutes"; |
| | | 32 | | readonly IMovementRouteService _movementRouteService; |
| | | 33 | | |
| | | 34 | | public MovementStatusRouteController(IMovementRouteService movementRouteService, ILogger<MovementStatusRouteCont |
| | 0 | 35 | | : base(logger) |
| | 0 | 36 | | { |
| | 0 | 37 | | _movementRouteService = movementRouteService; |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Возвращает регламенты статусов по складу |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="id">id склада</param> |
| | | 44 | | /// <returns></returns> |
| | | 45 | | [HttpGet("Department/{id}")] |
| | | 46 | | [SwaggerResponse(200, "Успешно", typeof(List<MovementStatusRouteResponseDTO>))] |
| | | 47 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 48 | | public async Task<IActionResult> GetRoutesByDepartment(long id) |
| | 0 | 49 | | { |
| | 0 | 50 | | var result = await _movementRouteService.GetRoutesByDepartment(id); |
| | 0 | 51 | | return Ok(ToDtoMapper().Map<List<MovementStatusRoute>, List<MovementStatusRouteResponseDTO>>(result)); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Возвращает регламент статуса по id |
| | | 56 | | /// </summary> |
| | | 57 | | /// <param name="id">id регламента</param> |
| | | 58 | | /// <returns></returns> |
| | | 59 | | [HttpGet("{id}")] |
| | | 60 | | [SwaggerResponse(200, "Успешно", typeof(List<MovementStatusRouteResponseDTO>))] |
| | | 61 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 62 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 63 | | public async Task<IActionResult> GetRoutes(long id) |
| | 0 | 64 | | { |
| | 0 | 65 | | var route = await _movementRouteService.GetRoute(id); |
| | 0 | 66 | | if (route == null) |
| | 0 | 67 | | { |
| | 0 | 68 | | throw new KeyNotFoundException($"Регламент не найден"); |
| | | 69 | | } |
| | 0 | 70 | | return Ok(ToDtoMapper().Map<MovementStatusRoute, MovementStatusRouteResponseDTO>(route)); |
| | 0 | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Обновляет регламент |
| | | 75 | | /// </summary> |
| | | 76 | | /// <param name="id">id регламента</param> |
| | | 77 | | /// <param name="data">данные для обновления</param> |
| | | 78 | | /// <returns></returns> |
| | | 79 | | [HttpPut("{id}")] |
| | | 80 | | [SwaggerResponse(200, "Успешно", typeof(MovementStatusRouteResponseDTO))] |
| | | 81 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 82 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 83 | | public async Task<IActionResult> Update(long id, MovementStatusRouteRequestDTO data) |
| | 0 | 84 | | { |
| | 0 | 85 | | var route = await _movementRouteService.GetRoute(id); |
| | 0 | 86 | | if (route == null) |
| | 0 | 87 | | { |
| | 0 | 88 | | throw new KeyNotFoundException($"Регламент не найден"); |
| | | 89 | | } |
| | 0 | 90 | | route.Hour = data.Hour; |
| | 0 | 91 | | await _movementRouteService.UpdateRoute(route); |
| | | 92 | | |
| | 0 | 93 | | return Ok(ToDtoMapper().Map<MovementStatusRoute, MovementStatusRouteResponseDTO>(route)); |
| | 0 | 94 | | } |
| | | 95 | | |
| | | 96 | | private static IMapper ToDtoMapper() |
| | 0 | 97 | | { |
| | 0 | 98 | | var config = new MapperConfiguration(cfg => |
| | 0 | 99 | | { |
| | 0 | 100 | | cfg.CreateMap<MovementStatusRoute, MovementStatusRouteResponseDTO>(); |
| | 0 | 101 | | cfg.CreateMap<Department, IdNameDTO>(); |
| | 0 | 102 | | cfg.CreateMap<MovementStatus, IdNameDTO>(); |
| | 0 | 103 | | }); |
| | 0 | 104 | | IMapper mapper = config.CreateMapper(); |
| | 0 | 105 | | return mapper; |
| | 0 | 106 | | } |
| | | 107 | | } |
| | | 108 | | } |