Skip to content

Commit

Permalink
⛏ Implement hook endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
furkandeveloper committed Aug 5, 2021
1 parent 99cd496 commit f17265c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions samples/IronHook.Web/Controllers/HookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,69 @@ public async Task<IActionResult> DeleteHookAsync([FromRoute] Guid id)
await hookService.RemoveAsync(hookId: id);
return NoContent();
}

/// <summary>
/// Add Request To Hook
/// </summary>
/// <param name="id">
/// PK of Hook Entity
/// </param>
/// <param name="model">
/// Hook Request Data Transfer Object
/// </param>
/// <returns>
/// OkObjectResult(Hook)
/// </returns>
[HttpPost("{id}/requests", Name = "AddRequestToHook")]
[ProducesResponseType(typeof(Hook), 200)]
public async Task<IActionResult> 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);
}

/// <summary>
/// Delete Hook Request
/// </summary>
/// <param name="id">
/// PK of Hook Request Entity
/// </param>
/// <returns></returns>
[HttpDelete("requests/{id}", Name = "DeleteHookRequest")]
[ProducesResponseType(204)]
public async Task<IActionResult> DeleteHookRequestAsync([FromRoute] Guid id)
{
await hookService.RemoveRequestAsync(id);
return NoContent();
}

/// <summary>
/// Get Hook Requests
/// </summary>
/// <param name="id">
/// PK of Hook
/// </param>
/// <returns>
/// List of Hook Request
/// </returns>
[HttpGet("requests/{id}", Name = "GetRequests")]
[ProducesResponseType(typeof(HookRequest[]), 200)]
public async Task<IActionResult> GetRequestsAsync([FromRoute] Guid id)
{
var response = await hookService.GetHookRequestsAsync(id);
return Ok(response);
}
}
}

0 comments on commit f17265c

Please sign in to comment.