48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
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
|
|
{
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|
public class RobotController : BaseApiController
|
|
{
|
|
private readonly IMapper mapper;
|
|
private readonly IRobotService robotService;
|
|
|
|
public RobotController(
|
|
IMapper mapper,
|
|
IRobotService robotService
|
|
)
|
|
{
|
|
this.mapper = mapper;
|
|
this.robotService = robotService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Получить список роботов
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(ApiRoutes.Robot.GetAll)]
|
|
public async Task<IActionResult> GetAll()
|
|
{
|
|
var robots = await robotService.Get().OrderBy(t => t.Code).ToListAsync();
|
|
|
|
if (!robots.Any())
|
|
return NoContent();
|
|
|
|
var response = mapper.Map<List<RobotResponse>>(robots);
|
|
|
|
return Ok(new Response<List<RobotResponse>>(response, true));
|
|
}
|
|
}
|
|
}
|