From 5c21f6d3223e7ef1ad11e25bea09639decb889b3 Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Wed, 8 May 2024 14:47:18 +1000 Subject: [PATCH] feat(api): RobotController get all --- PARR.API/Contracts/V1/ApiRoutes.cs | 5 +++ PARR.API/Controllers/V1/RobotController.cs | 47 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 PARR.API/Controllers/V1/RobotController.cs diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs index 7b05428e..0c87ad44 100644 --- a/PARR.API/Contracts/V1/ApiRoutes.cs +++ b/PARR.API/Contracts/V1/ApiRoutes.cs @@ -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/"; diff --git a/PARR.API/Controllers/V1/RobotController.cs b/PARR.API/Controllers/V1/RobotController.cs new file mode 100644 index 00000000..f3125c98 --- /dev/null +++ b/PARR.API/Controllers/V1/RobotController.cs @@ -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; + } + + + /// + /// Получить список роботов + /// + /// + [HttpGet(ApiRoutes.Robot.GetAll)] + public async Task GetAll() + { + var robots = await robotService.Get().OrderBy(t => t.Code).ToListAsync(); + + if (!robots.Any()) + return NoContent(); + + var response = mapper.Map>(robots); + + return Ok(new Response>(response, true)); + } + } +}