| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | |
| | | 3 | | namespace Estud.Mocks.Webhooks; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Simula o sistema target de um cliente que configurou um webhook no Estud. |
| | | 7 | | /// Ecoa de volta os headers e o corpo recebidos para que os testes possam |
| | | 8 | | /// validar a entrega ponta a ponta, incluindo os custom headers configurados |
| | | 9 | | /// na assinatura do webhook. |
| | | 10 | | /// </summary> |
| | | 11 | | [ApiController] |
| | | 12 | | public class WebhookTargetController : ControllerBase |
| | | 13 | | { |
| | | 14 | | [HttpPost("webhooks/target")] |
| | | 15 | | public async Task<IActionResult> Receive() |
| | | 16 | | { |
| | 16 | 17 | | using var reader = new StreamReader(Request.Body); |
| | 16 | 18 | | var body = await reader.ReadToEndAsync(); |
| | | 19 | | |
| | 116 | 20 | | var headers = Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString()); |
| | | 21 | | |
| | 16 | 22 | | return Ok(new { received = true, headers, body }); |
| | 16 | 23 | | } |
| | | 24 | | |
| | | 25 | | [HttpPost("webhooks/target/error")] |
| | | 26 | | public IActionResult ReceiveWithError() |
| | | 27 | | { |
| | 2 | 28 | | return StatusCode(500, new { received = false, error = "target system unavailable" }); |
| | | 29 | | } |
| | | 30 | | } |