initial commit

This commit is contained in:
2026-04-15 15:02:32 +02:00
commit 3bfc79e6d9
1380 changed files with 69684 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Events.Interfaces;
using Microsoft.SelfService.Portal.Core.API.Models;
namespace Microsoft.SelfService.Portal.Core.API.Controllers
{
public class AbstractController : Controller
{
private readonly IEventHandlerInterface _eventHandlerInterface;
private readonly string _class;
private readonly string _method;
public AbstractController( string Class, string Method)
{
}
[NonAction]
ICollection<EventModel> GetEvents()
{
return _eventHandlerInterface.GetEvents(_class, _method);
}
}
}

View File

@@ -0,0 +1,135 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Deployment.Add;
using Microsoft.SelfService.Portal.Core.API.Dto.Deployment.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.Deployment.Edit;
using Microsoft.SelfService.Portal.Core.API.Interfaces;
using Microsoft.SelfService.Portal.Core.API.Models;
using Microsoft.SelfService.Portal.Core.API.Events.Interfaces;
using System.Reflection;
using System.Collections;
using System.Dynamic;
using System.Text.Json;
namespace Microsoft.SelfService.Portal.Core.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DeploymentController : Controller
{
private readonly IDeploymentInterface _deploymentInterface;
private readonly IMapper _mapper;
private readonly IEventHandlerInterface _eventHandlerInterface;
public DeploymentController(IDeploymentInterface deploymentInterface, IMapper mapper, IEventHandlerInterface eventHandlerInterface)
{
_deploymentInterface = deploymentInterface;
_mapper = mapper;
_eventHandlerInterface = eventHandlerInterface;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<DeploymentModel>))]
public IActionResult GetDeployments()
{
var deployment = _mapper.Map<List<GetDeploymentDto>>(_deploymentInterface.GetDeployments());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(deployment);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(DeploymentModel))]
[ProducesResponseType(400)]
public IActionResult GetDeploymentById(Guid Id)
{
if (!_deploymentInterface.CheckDeploymentById(Id))
return NotFound();
var deployment = _mapper.Map<GetDeploymentDetailsDto>(_deploymentInterface.GetDeploymentById(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(deployment);
}
[HttpPost]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public IActionResult AddDeploymentById([FromBody] AddDeploymentDto deployment)
{
if (deployment == null)
return BadRequest(ModelState);
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deploymentMap = _mapper.Map<DeploymentModel>(deployment);
if (!_deploymentInterface.AddDeploymentById(deploymentMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
return Ok(deploymentMap.Id);
}
[HttpDelete("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult DeleteDeploymentById(Guid Id)
{
if (!_deploymentInterface.CheckDeploymentById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deployment = _deploymentInterface.GetDeploymentById(Id);
if (!_deploymentInterface.DeleteDeploymentById(deployment))
{
ModelState.AddModelError("", "Something went wrong while deleting");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpPut("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult EditDeploymentById(Guid Id, [FromBody] EditDeploymentDto deployment)
{
if (deployment == null)
return BadRequest(ModelState);
if (!_deploymentInterface.CheckDeploymentById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deploymentMap = _mapper.Map<DeploymentModel>(deployment);
deploymentMap.Id = Id;
if (!_deploymentInterface.EditDeploymentById(deploymentMap))
{
ModelState.AddModelError("", "Something went wrong");
return StatusCode(500, ModelState);
}
_eventHandlerInterface.FireEvent(this.GetType().Name, MethodBase.GetCurrentMethod().Name, Id);
return NoContent();
}
}
}

View File

@@ -0,0 +1,125 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.DeploymentGroup.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.DeploymentGroup.Add;
using Microsoft.SelfService.Portal.Core.API.Dto.DeploymentGroup.Edit;
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 DeploymentGroupController : Controller
{
private readonly IDeploymentGroupInterface _deploymentgroupInterface;
private readonly IMapper _mapper;
public DeploymentGroupController(IDeploymentGroupInterface deploymentGroupInterface, IMapper mapper)
{
_deploymentgroupInterface = deploymentGroupInterface;
_mapper = mapper;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<DomainModel>))]
public IActionResult GetDeploymentGroups()
{
var deploymentgroups = _mapper.Map<List<GetDeploymentGroupDto>>(_deploymentgroupInterface.GetDeploymentGroups());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(deploymentgroups);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(DeploymentGroupModel))]
[ProducesResponseType(400)]
public IActionResult GetDeploymentGroupById(Guid Id)
{
if (!_deploymentgroupInterface.CheckDeploymentGroupById(Id))
return NotFound();
var deploymentgroup = _mapper.Map<GetDeploymentGroupDetailsDto>(_deploymentgroupInterface.GetDeploymentGroupById(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(deploymentgroup);
}
[HttpPost]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public IActionResult AddDeploymentGroupById([FromBody] AddDeploymentGroupDto deploymentgroup)
{
if (deploymentgroup == null)
return BadRequest(ModelState);
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deploymentgroupMap = _mapper.Map<DeploymentGroupModel>(deploymentgroup);
if (!_deploymentgroupInterface.AddDeploymentGroupById(deploymentgroupMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
return Ok(deploymentgroupMap.Id);
}
[HttpDelete("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult DeleteDeploymentGroupById(Guid Id)
{
if (!_deploymentgroupInterface.CheckDeploymentGroupById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deploymentgroup = _deploymentgroupInterface.GetDeploymentGroupById(Id);
if (!_deploymentgroupInterface.DeleteDeploymentGroupById(deploymentgroup))
{
ModelState.AddModelError("", "Something went wrong while deleting");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpPut("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult EditDeploymentGroupById(Guid Id, [FromBody] EditDeploymentGroupDto deploymentgroup)
{
if (deploymentgroup == null)
return BadRequest(ModelState);
if (!_deploymentgroupInterface.CheckDeploymentGroupById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var deploymentgroupMap = _mapper.Map<DeploymentGroupModel>(deploymentgroup);
deploymentgroupMap.Id = Id;
if (!_deploymentgroupInterface.EditDeploymentGroupById(deploymentgroupMap))
{
ModelState.AddModelError("", "Something went wrong");
return StatusCode(500, ModelState);
}
return NoContent();
}
}
}

View File

@@ -0,0 +1,230 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Domain.Add;
using Microsoft.SelfService.Portal.Core.API.Dto.Domain.Edit;
using Microsoft.SelfService.Portal.Core.API.Dto.Domain.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 DomainController : Controller
{
private readonly IDomainInterface _domainInterface;
private readonly IEnvironmentInterface _environmentInterface;
private readonly IMapper _mapper;
public DomainController(IDomainInterface domainInterface,IEnvironmentInterface environmentInterface, IMapper mapper)
{
_domainInterface = domainInterface;
_environmentInterface = environmentInterface;
_mapper = mapper;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<DomainModel>))]
public IActionResult GetDomains()
{
var domains = _mapper.Map<List<GetDomainDto>>(_domainInterface.GetDomains());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(domains);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(DomainModel))]
[ProducesResponseType(400)]
public IActionResult GetDomainById(Guid Id)
{
if (!_domainInterface.CheckDomainById(Id))
return NotFound();
var domain = _mapper.Map<GetDomainDetailsDto>(_domainInterface.GetDomainById(Id));
if(!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(domain);
}
[HttpPost]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public IActionResult AddDomainById([FromBody] AddDomainDto domain)
{
if (domain == null)
return BadRequest(ModelState);
if (_domainInterface.CheckDomainByName(domain.Name))
{
ModelState.AddModelError("", "Domain already exists");
return StatusCode(422, ModelState);
}
if (!ModelState.IsValid)
return BadRequest(ModelState);
var domainMap = _mapper.Map<DomainModel>(domain);
if (!_domainInterface.AddDomainById(domainMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
//return Ok("Successfully created");
return Ok(domainMap.Id);
}
[HttpDelete("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult DeleteDomainById(Guid Id)
{
if (!_domainInterface.CheckDomainById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var domain = _domainInterface.GetDomainById(Id);
if (!_domainInterface.DeleteDomainById(domain))
{
ModelState.AddModelError("", "Something went wrong while deleting");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpPut("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult EditDomainById(Guid Id, [FromBody] EditDomainDto domain)
{
if (domain == null)
return BadRequest(ModelState);
if (!_domainInterface.CheckDomainById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var domainMap = _mapper.Map<DomainModel>(domain);
domainMap.Id = Id;
if (!_domainInterface.EditDomainById(domainMap))
{
ModelState.AddModelError("", "Something went wrong");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpGet("{Id}/Environments")]
[ProducesResponseType(200, Type = typeof(DomainModel))]
[ProducesResponseType(400)]
public IActionResult GetDomainByIdInEnvironments(Guid Id)
{
if (!_domainInterface.CheckDomainById(Id))
return NotFound();
var domain = _mapper.Map<GetDomainEnvironmentDto>(_domainInterface.GetDomainByIdInEnvironments(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(domain);
}
[HttpPost("{DomainId}/Environment/{EnvironmentId}")]
[ProducesResponseType(200, Type = typeof(EnvironmentDomainsModel))]
[ProducesResponseType(400)]
public IActionResult LinkDomainByIdToEnvironment(Guid DomainId, Guid EnvironmentId)
{
if(!_domainInterface.CheckDomainById(DomainId))
return new NotFoundObjectResult("Domain with Id was not found");
if(!_environmentInterface.CheckEnvironmentById(EnvironmentId))
return new NotFoundObjectResult("Environment with Id was not found");
if (!ModelState.IsValid)
return BadRequest(ModelState);
var environmentDomain = new EnvironmentDomainsModel
{
DomainId = DomainId,
Domain = _domainInterface.GetDomainById(DomainId),
EnvironmentId = EnvironmentId,
Environment = _environmentInterface.GetEnvironmentById(EnvironmentId)
};
var environmentDomainMap = _mapper.Map<EnvironmentDomainsModel>(environmentDomain);
if (!_domainInterface.LinkDomainByIdToEnvironment(environmentDomainMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
return Ok("Successfully created");
}
[HttpDelete("{DomainId}/Environment/{EnvironmentId}")]
[ProducesResponseType(200, Type = typeof(EnvironmentDomainsModel))]
[ProducesResponseType(400)]
public IActionResult UnlinkDomainByIdFromEnvironment(Guid DomainId, Guid EnvironmentId)
{
if (!_domainInterface.CheckDomainById(DomainId) & !_environmentInterface.CheckEnvironmentById(EnvironmentId))
return new NotFoundObjectResult("Domain with Id is not linked to Environment");
if (!ModelState.IsValid)
return BadRequest(ModelState);
var environmentDomain = new EnvironmentDomainsModel
{
DomainId = DomainId,
Domain = _domainInterface.GetDomainById(DomainId),
EnvironmentId = EnvironmentId,
Environment = _environmentInterface.GetEnvironmentById(EnvironmentId)
};
if (!_domainInterface.UnlinkDomainByIdFromEnvironment(environmentDomain))
{
ModelState.AddModelError("", "Something went wrong while deleting");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpGet("{Id}/VirtualMachines")]
[ProducesResponseType(200, Type = typeof(DomainModel))]
[ProducesResponseType(400)]
public IActionResult GetVirtualMachinesByDomainId(Guid Id)
{
if (!_domainInterface.CheckDomainById(Id))
return NotFound();
var domain = _mapper.Map<GetDomainVirtualMachineDetailsDto>(_domainInterface.GetVirtualMachinesByDomainId(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(domain);
}
}
}

View File

@@ -0,0 +1,162 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Environment.Add;
using Microsoft.SelfService.Portal.Core.API.Dto.Environment.Edit;
using Microsoft.SelfService.Portal.Core.API.Dto.Environment.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.Service.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.Template.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 EnvironmentController : Controller
{
private readonly IEnvironmentInterface _environmentInterface;
private readonly IMapper _mapper;
public EnvironmentController(IEnvironmentInterface environmentInterface, IMapper mapper)
{
_environmentInterface = environmentInterface;
_mapper = mapper;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<EnvironmentModel>))]
public IActionResult GetEnvironments()
{
var environments = _mapper.Map<List<GetEnvironmentDto>>(_environmentInterface.GetEnvironments());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(environments);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(EnvironmentModel))]
[ProducesResponseType(400)]
public IActionResult GetEnvironmentByID(Guid Id)
{
if (!_environmentInterface.CheckEnvironmentById(Id))
return NotFound();
var environment = _mapper.Map<GetEnvironmentDetailsDto>(_environmentInterface.GetEnvironmentById(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(environment);
}
[HttpPost]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public IActionResult AddEnvironmentById([FromBody] AddEnvironmentDto environment)
{
if (environment == null)
return BadRequest(ModelState);
if (_environmentInterface.CheckEnvironmentByName(environment.Name))
{
ModelState.AddModelError("", "Domain already exists");
return StatusCode(422, ModelState);
}
if (!ModelState.IsValid)
return BadRequest(ModelState);
var environmentMap = _mapper.Map<EnvironmentModel>(environment);
if (!_environmentInterface.AddEnvironmentById(environmentMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
return Ok("Successfully created");
}
[HttpDelete("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult DeleteEnvironmentById(Guid Id)
{
if (!_environmentInterface.CheckEnvironmentById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var domain = _environmentInterface.GetEnvironmentById(Id);
if (!_environmentInterface.DeleteEnvironmentById(domain))
{
ModelState.AddModelError("", "Something went wrong while deleting");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpPut("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult EditDomainById(Guid Id, [FromBody] EditEnvironmentDto environment)
{
if (environment == null)
return BadRequest(ModelState);
if (!_environmentInterface.CheckEnvironmentById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var environmentMap = _mapper.Map<EnvironmentModel>(environment);
environmentMap.Id = Id;
if (!_environmentInterface.EditEnvironmentById(environmentMap))
{
ModelState.AddModelError("", "Something went wrong");
return StatusCode(500, ModelState);
}
return NoContent();
}
[HttpGet("{Id}/Domains")]
[ProducesResponseType(200, Type = typeof(EnvironmentModel))]
[ProducesResponseType(400)]
public IActionResult GetLinkedDomainsByEnvironmentId(Guid Id)
{
if (!_environmentInterface.CheckEnvironmentById(Id))
return NotFound();
var environment = _mapper.Map<GetEnvironmentDomainDto>(_environmentInterface.GetLinkedDomainsByEnvironmentId(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(environment);
}
[HttpGet("{Id}/Templates")]
[ProducesResponseType(200, Type = typeof(IEnumerable<TemplateModel>))]
public IActionResult GetAvailableTemplatesByEnvironmentId(Guid Id)
{
var templates = _mapper.Map<List<GetTemplateDetailsDto>>(_environmentInterface.GetAvailableTemplatesByEnvironmentId(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(templates);
}
}
}

View File

@@ -0,0 +1,113 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Runbook.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.Runbook.Add;
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 RunbookController : Controller
{
private readonly IRunbookInterface _runbookInterface;
private readonly IMapper _mapper;
public RunbookController(IRunbookInterface runbookInterface, IMapper mapper)
{
_runbookInterface = runbookInterface;
_mapper = mapper;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<RunbookModel>))]
public IActionResult GetRunbooks()
{
var runbooks = _mapper.Map<List<GetRunbookDto>>(_runbookInterface.GetRunbooks());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(runbooks);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(RunbookModel))]
[ProducesResponseType(400)]
public IActionResult GetRunbookById(Guid Id)
{
if (!_runbookInterface.CheckRunbookById(Id))
return NotFound();
var runbook = _mapper.Map<GetRunbookDetailsDto>(_runbookInterface.GetRunbookById(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(runbook);
}
[HttpPost]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public IActionResult AddRunbookById([FromBody] AddRunbookDto runbook)
{
if (runbook == null)
return BadRequest(ModelState);
if (_runbookInterface.CheckRunbookByName(runbook.Name))
{
ModelState.AddModelError("", "Runbook already exists");
return StatusCode(422, ModelState);
}
if (!ModelState.IsValid)
return BadRequest(ModelState);
var runbookMap = _mapper.Map<RunbookModel>(runbook);
if (!_runbookInterface.AddRunbookById(runbookMap))
{
ModelState.AddModelError("", "Something went wrong while saving");
return StatusCode(500, ModelState);
}
return Ok("Successfully created");
}
[HttpPut("{Id}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult EditRunbookById(Guid Id, [FromBody] GetRunbookDetailsDto runbook)
{
if (runbook == null)
return BadRequest(ModelState);
if (Id != runbook.Id)
return BadRequest(ModelState);
if (!_runbookInterface.CheckRunbookById(Id))
return NotFound();
if (!ModelState.IsValid)
return BadRequest(ModelState);
var runbookMap = _mapper.Map<RunbookModel>(runbook);
if (_runbookInterface.EditRunbookById(runbookMap))
{
ModelState.AddModelError("", "Something went wrong");
return StatusCode(500, ModelState);
}
return NoContent();
}
}
}

View File

@@ -0,0 +1,51 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Service.Get;
using Microsoft.SelfService.Portal.Core.API.Events;
using Microsoft.SelfService.Portal.Core.API.Events.Interfaces;
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 ServiceController : Controller
{
private readonly IMapper _mapper;
private readonly IServiceInterface _serviceInterface;
public ServiceController(IMapper mapper, IServiceInterface serviceInterface)
{
_mapper = mapper;
_serviceInterface = serviceInterface;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<ServiceModel>))]
public IActionResult GetServices()
{
var services = _mapper.Map<List<GetServiceDto>>(_serviceInterface.GetServices());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(services);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(ServiceModel))]
public IActionResult GetServiceById(Guid Id)
{
if(!_serviceInterface.CheckServiceById(Id))
return NotFound();
var service = _mapper.Map<GetServiceDetailsDto>(_serviceInterface.GetServiceById(Id));
if(!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(service);
}
}
}

View File

@@ -0,0 +1,51 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SelfService.Portal.Core.API.Dto.Service.Get;
using Microsoft.SelfService.Portal.Core.API.Dto.Template.Get;
using Microsoft.SelfService.Portal.Core.API.Interfaces;
using Microsoft.SelfService.Portal.Core.API.Models;
using System.Reflection;
namespace Microsoft.SelfService.Portal.Core.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TemplateController : Controller
{
private readonly ITemplateInterface _templateInterface;
private readonly IMapper _mapper;
public TemplateController(ITemplateInterface templateInterface, IMapper mapper)
{
_templateInterface = templateInterface;
_mapper = mapper;
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<TemplateModel>))]
public IActionResult GetTemplates()
{
var templates = _mapper.Map<List<GetTemplateDto>>(_templateInterface.GetTemplates());
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(templates);
}
[HttpGet("{Id}")]
[ProducesResponseType(200, Type = typeof(TemplateModel))]
public IActionResult GetTemplateById(Guid Id)
{
if (!_templateInterface.CheckTemplateById(Id))
return NotFound();
var template = _mapper.Map<GetTemplateDetailsDto>(_templateInterface.GetTemplateById(Id));
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok(template);
}
}
}

View 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);
}
}
}