feat(api): RobotController get all

This commit is contained in:
Mikhail Trubnikov
2024-05-08 14:47:18 +10:00
parent 079415a40e
commit 5c21f6d322
2 changed files with 52 additions and 0 deletions

View File

@@ -78,6 +78,11 @@
public const string templateId = "{templateId}";
}
public static class Robot
{
public const string GetAll = Base + "/robots/";
}
public static class RobotHistory
{
public const string GetAll = Base + "/robot-histories/";

View File

@@ -0,0 +1,47 @@
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));
}
}
}