using AutoMapper; using Microsoft.AspNetCore.Mvc; using Microsoft.SelfService.Portal.Core.API.Dto.VirtualMachine.Get; using Microsoft.SelfService.Portal.Core.API.Interfaces; using Microsoft.SelfService.Portal.Core.API.Models; namespace Microsoft.SelfService.Portal.Core.API.Controllers { [Route("api/[controller]")] [ApiController] public class VirtualMachineController : Controller { private readonly IVirtualMachineInterface _virtualmachineInterface; private readonly IMapper _mapper; public VirtualMachineController(IVirtualMachineInterface virtualmachineInterface, IMapper mapper) { _virtualmachineInterface = virtualmachineInterface; _mapper = mapper; } [HttpGet] [ProducesResponseType(200, Type = typeof(IEnumerable))] public IActionResult GetVirtualMachines() { var virtualmachines = _mapper.Map>(_virtualmachineInterface.GetVirtualMachines()); if (!ModelState.IsValid) return BadRequest(ModelState); return Ok(virtualmachines); } [HttpGet("{Id}")] [ProducesResponseType(200, Type = typeof(VirtualMachineModel))] [ProducesResponseType(400)] public IActionResult GetVirtualMachineById(Guid Id) { if (!_virtualmachineInterface.CheckVirtualMachineById(Id)) return NotFound(); var virtualmachines = _mapper.Map(_virtualmachineInterface.GetVirtualMachineById(Id)); if(!ModelState.IsValid) return BadRequest(ModelState); return Ok(virtualmachines); } } }