initial commit
This commit is contained in:
51
Controllers/VirtualMachineController.cs
Normal file
51
Controllers/VirtualMachineController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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<VirtualMachineModel>))]
|
||||
public IActionResult GetVirtualMachines()
|
||||
{
|
||||
var virtualmachines = _mapper.Map<List<GetVirtualMachineDto>>(_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<GetVirtualMachineDetailsDto>(_virtualmachineInterface.GetVirtualMachineById(Id));
|
||||
|
||||
if(!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
return Ok(virtualmachines);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user