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