namespace Diligent.WebAPI.Host.Controllers.V1
{
[ApiVersion("1.0")]
[ApiController]
[Route("v{version:apiVersion}/webhooks")]
public class WebhooksController : ControllerBase
{
private readonly IWebhookSubscriptionService _webhookSubscriptionService;
private readonly IWebhookDefinitionService _webhookDefinitionService;
public WebhooksController(
IWebhookSubscriptionService subscriptionService,
IWebhookDefinitionService definitionsService)
{
_webhookSubscriptionService = subscriptionService;
_webhookDefinitionService = definitionsService;
}
///
/// Create webhook subscription
///
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ErrorResponseDto), StatusCodes.Status400BadRequest)]
public async Task Post([FromBody] WebhookSubscriptionCreateDto dto)
{
await _webhookSubscriptionService.CreateWebhookSubscription(dto);
return StatusCode(StatusCodes.Status201Created);
}
///
/// Get all webhook definitions
///
[HttpGet("definitions")]
[ProducesResponseType(typeof(List), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponseDto), StatusCodes.Status400BadRequest)]
public async Task GetDefinitions()
{
return Ok(await _webhookDefinitionService.GetAll());
}
}
}