Skip to content

Commit 4d0c4fd

Browse files
committed
✨ add healthcheck endpoint
1 parent aa5dcd0 commit 4d0c4fd

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using WebhookRelayService.Services;
3+
4+
namespace WebhookRelayService.Controllers
5+
{
6+
[Route("api/[controller]")]
7+
public class HealthCheckController : ControllerBase
8+
{
9+
private IWebhookUserService _webhookUserService;
10+
11+
public HealthCheckController(IWebhookUserService webhookUserService)
12+
{
13+
_webhookUserService = webhookUserService;
14+
}
15+
16+
[HttpGet]
17+
public async Task<int> HealthCheck()
18+
{
19+
return await _webhookUserService.GetRegisteredUsersCount();
20+
}
21+
}
22+
}

WebhookRelayService/Repositories/WebhookUserRepository.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IWebhookUserRepository
1010
public Task<WebhookUser> GetById(Guid id);
1111
public Task<WebhookUser?> GetByWebhookId(int id);
1212
public Task Delete(WebhookUser webhookUser);
13+
public Task<int> Count();
1314
}
1415

1516
public class WebhookUserRepository : IWebhookUserRepository
@@ -50,5 +51,10 @@ public async Task Delete(WebhookUser webhookUser)
5051
_context.WebhookUsers.Remove(webhookUser);
5152
await _context.SaveChangesAsync();
5253
}
54+
55+
public async Task<int> Count()
56+
{
57+
return await _context.WebhookUsers.CountAsync();
58+
}
5359
}
5460
}

WebhookRelayService/Services/WebhookUserService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IWebhookUserService
88
{
99
public Task<Guid> Create(WebhookUserCreateDTO dto);
1010
public Task Delete(Guid id);
11+
public Task<int> GetRegisteredUsersCount();
1112
}
1213

1314
public class WebhookUserService : IWebhookUserService
@@ -43,6 +44,11 @@ public async Task Delete(Guid id)
4344
await _repository.Delete(user);
4445
}
4546

47+
public async Task<int> GetRegisteredUsersCount()
48+
{
49+
return await _repository.Count();
50+
}
51+
4652
private async Task<bool> CheckEndpoint(string endpoint)
4753
{
4854
var httpResponse = await _httpService.SendGet(endpoint);

0 commit comments

Comments
 (0)