feat(api): RobotController get all
This commit is contained in:
@@ -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/";
|
||||
|
||||
47
PARR.API/Controllers/V1/RobotController.cs
Normal file
47
PARR.API/Controllers/V1/RobotController.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user