diff --git a/samples/IronHook.Web/Controllers/HookController.cs b/samples/IronHook.Web/Controllers/HookController.cs index 8359212..457edb8 100644 --- a/samples/IronHook.Web/Controllers/HookController.cs +++ b/samples/IronHook.Web/Controllers/HookController.cs @@ -157,5 +157,69 @@ public async Task DeleteHookAsync([FromRoute] Guid id) await hookService.RemoveAsync(hookId: id); return NoContent(); } + + /// + /// Add Request To Hook + /// + /// + /// PK of Hook Entity + /// + /// + /// Hook Request Data Transfer Object + /// + /// + /// OkObjectResult(Hook) + /// + [HttpPost("{id}/requests", Name = "AddRequestToHook")] + [ProducesResponseType(typeof(Hook), 200)] + public async Task AddRequestToHookAsync([FromRoute] Guid id, [FromBody] HookRequestDefineDto model) + { + var hook = await hookService.GetAsync(x => x.Id == id && x.TenantId == "1" && x.IsDeleted == false); + var hookData = hook.FirstOrDefault(); + hookData.HookRequests.Add(new HookRequest + { + Method = model.Method, + Url = model.Url, + NotifiyEmail = model.NotifyEmail, + MaxRetryCount = model.MaxRetryCount, + Headers = JsonSerializer.Serialize(model.HeaderParameters) + }); + + await hookService.UpdateAsync(hookData); + + return Ok(hookData); + } + + /// + /// Delete Hook Request + /// + /// + /// PK of Hook Request Entity + /// + /// + [HttpDelete("requests/{id}", Name = "DeleteHookRequest")] + [ProducesResponseType(204)] + public async Task DeleteHookRequestAsync([FromRoute] Guid id) + { + await hookService.RemoveRequestAsync(id); + return NoContent(); + } + + /// + /// Get Hook Requests + /// + /// + /// PK of Hook + /// + /// + /// List of Hook Request + /// + [HttpGet("requests/{id}", Name = "GetRequests")] + [ProducesResponseType(typeof(HookRequest[]), 200)] + public async Task GetRequestsAsync([FromRoute] Guid id) + { + var response = await hookService.GetHookRequestsAsync(id); + return Ok(response); + } } }