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,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();
}
}
}