initial commit
This commit is contained in:
125
Controllers/DeploymentGroupController.cs
Normal file
125
Controllers/DeploymentGroupController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user