Skip to content

Commit ff9c1ee

Browse files
authored
Merge pull request #9 from Skyfall1235/minor-webhook-changes
moved webhook stuff into the namespace
2 parents 4b80a7c + b573234 commit ff9c1ee

File tree

8 files changed

+59
-48
lines changed

8 files changed

+59
-48
lines changed
Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
using Microsoft.AspNetCore.Mvc;
22
using RandomAPI.Models;
3-
using RandomAPI.Services.Webhooks;
4-
5-
public interface IWebhookService
3+
namespace RandomAPI.Services.Webhooks
64
{
7-
// Basel class methods
8-
/// <summary>
9-
/// Sends a webhook notification to all registered listeners.
10-
/// </summary>
11-
Task BroadcastAsync<T>(T payload) where T : class;
5+
public interface IWebhookService
6+
{
7+
// Basel class methods
8+
/// <summary>
9+
/// Sends a webhook notification to all registered listeners.
10+
/// </summary>
11+
Task BroadcastAsync<T>(T payload) where T : class;
1212

13-
/// <summary>
14-
/// Registers a new webhook listener URL.
15-
/// </summary>
16-
/// <returns>True if added, false if it already existed.</returns>
17-
Task AddListenerAsync(string url, WebhookType type = default);
13+
/// <summary>
14+
/// Registers a new webhook listener URL.
15+
/// </summary>
16+
/// <returns>True if added, false if it already existed.</returns>
17+
Task AddListenerAsync(string url, WebhookType type = default);
1818

19-
/// <summary>
20-
/// Removes a webhook listener URL.
21-
/// </summary>
22-
/// <returns>True if removed, false if not found.</returns>
23-
Task<bool> RemoveListenerAsync(string url);
19+
/// <summary>
20+
/// Removes a webhook listener URL.
21+
/// </summary>
22+
/// <returns>True if removed, false if not found.</returns>
23+
Task<bool> RemoveListenerAsync(string url);
2424

25-
/// <summary>
26-
/// Returns a snapshot of all registered listener URLs.
27-
/// </summary>
28-
Task<IEnumerable<string>> GetListenersAsync();
25+
/// <summary>
26+
/// Returns a snapshot of all registered listener URLs.
27+
/// </summary>
28+
Task<IEnumerable<string>> GetListenersAsync();
2929

30-
/// <summary>
31-
/// returns a snapshot of all registered listenrs of a given type
32-
/// </summary>
33-
/// <param name="type"> the type of url</param>
34-
Task<IEnumerable<string>> GetListenersAsync(WebhookType type = WebhookType.Default);
30+
/// <summary>
31+
/// returns a snapshot of all registered listenrs of a given type
32+
/// </summary>
33+
/// <param name="type"> the type of url</param>
34+
Task<IEnumerable<string>> GetListenersAsync(WebhookType type = WebhookType.Default);
3535

36-
// Controller Logic Methods (Implemented in the derived class)
37-
public Task<IActionResult> HandleGetListenersActionAsync();
38-
public Task<IActionResult> HandleGetListenersOfTypeAsync(WebhookType type);
39-
public Task<IActionResult> HandleRegisterActionAsync(string url, WebhookType type = default);
40-
public Task<IActionResult> HandleUnregisterActionAsync(string url);
41-
public Task<IActionResult> HandleBroadcastActionAsync(IWebHookPayload payload);
36+
// Controller Logic Methods (Implemented in the derived class)
37+
public Task<IActionResult> HandleGetListenersActionAsync();
38+
public Task<IActionResult> HandleGetListenersOfTypeAsync(WebhookType type);
39+
public Task<IActionResult> HandleRegisterActionAsync(string url, WebhookType type = default);
40+
public Task<IActionResult> HandleUnregisterActionAsync(string url);
41+
public Task<IActionResult> HandleBroadcastActionAsync(IWebHookPayload payload);
4242

43-
public enum WebhookType
44-
{
45-
Default = 0,
46-
Discord = 1,
47-
Logging = 2,
43+
public enum WebhookType
44+
{
45+
Default = 0,
46+
Discord = 1,
47+
Logging = 2,
48+
}
4849
}
4950
}
51+

src/RandomAPI/APIServices/Services/BaseWebhookService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using RandomAPI.Repository;
2-
using static IWebhookService;
32

43
namespace RandomAPI.Services.Webhooks
54
{
@@ -21,13 +20,13 @@ public async Task<IEnumerable<string>> GetListenersAsync()
2120
return urls.Select(u => u.Url);
2221
}
2322

24-
public async Task<IEnumerable<string>> GetListenersAsync(WebhookType type = WebhookType.Default)
23+
public async Task<IEnumerable<string>> GetListenersAsync(IWebhookService.WebhookType type = IWebhookService.WebhookType.Default)
2524
{
2625
var urls = await _repo.GetUrlsOfTypeAsync(type);
2726
return urls.Select(u => u.Url);
2827
}
2928

30-
public async Task AddListenerAsync(string url, WebhookType type = default)
29+
public async Task AddListenerAsync(string url, IWebhookService.WebhookType type = default)
3130
{
3231
await _repo.AddUrlAsync(url, type);
3332
}

src/RandomAPI/APIServices/Services/WebhookActionService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22
using RandomAPI.Models;
33
using RandomAPI.Repository;
4-
using static IWebhookService;
54

65
namespace RandomAPI.Services.Webhooks
76
{
@@ -16,7 +15,7 @@ public async Task<IActionResult> HandleGetListenersActionAsync()
1615
return new OkObjectResult(urls);
1716
}
1817

19-
public async Task<IActionResult> HandleGetListenersOfTypeAsync(WebhookType type)
18+
public async Task<IActionResult> HandleGetListenersOfTypeAsync(IWebhookService.WebhookType type)
2019
{
2120
var urls = await base.GetListenersAsync(type);
2221
return new OkObjectResult(urls);
@@ -26,7 +25,7 @@ public async Task<IActionResult> HandleRegisterActionAsync([FromBody] string url
2625
{
2726
if (string.IsNullOrWhiteSpace(url))
2827
return new BadRequestObjectResult("URL cannot be empty.");
29-
//neede both on regisdter and deregister
28+
//needed both on regisdter and deregister
3029
string safeUrlForLog = SanitizeURL(ref url);
3130

3231
await base.AddListenerAsync(url, type);
@@ -89,7 +88,7 @@ public async Task<IActionResult> HandleBroadcastActionAsync([FromBody] IWebHookP
8988
private static string SanitizeURL(ref string url)
9089
{
9190
url = url.Trim();
92-
var safeUrlForLog = url.Replace("\r", "").Replace("\n", "");
91+
string? safeUrlForLog = url.Replace("\r", "").Replace("\n", "");
9392
return safeUrlForLog;
9493
}
9594
}

src/RandomAPI/Controllers/WebhookController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22
using RandomAPI.Services.Webhooks;
3-
using static IWebhookService;
3+
44

55
namespace RandomAPI.Controllers
66
{
@@ -43,7 +43,7 @@ public async Task<IActionResult> RegisterUrl([FromBody] string url)
4343
[HttpPost("register-discord")]
4444
public async Task<IActionResult> RegisterDiscordUrl([FromBody] string url)
4545
{
46-
return await _webhookService.HandleRegisterActionAsync(url, WebhookType.Discord);
46+
return await _webhookService.HandleRegisterActionAsync(url, IWebhookService.WebhookType.Discord);
4747
}
4848

4949
/// <summary>

src/RandomAPI/Models/WebhookUrl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
namespace RandomAPI.Models
2+
namespace RandomAPI.Services.Webhooks
33
{
44
/// <summary>
55
/// Represents a registered webhook listener URL stored in the database.

src/RandomAPI/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
// TODO:
7979
// - good logging service. rabapp has an event table, i bet i could do something worse
8080

81+
// date idea generator based on a list of ideas and an energy rating. should have a table of all ideas, endpoints to review what exists, and display the most recent selection from both parties
82+
83+
// idea - email checker that notifies me when a meeting time is moved or canceled for rabapp
84+
85+
//
86+
8187
// - AlertGatewayService
8288
// API Endpoint Goal: POST / alert / ingest
8389
// Brief Description(Project Scope): Centralized Notification Hub with Discord Integration.
@@ -97,3 +103,6 @@ public class HealthCheckService { }
97103
// A CRUD API to save and retrieve frequently forgotten code snippets, complex CLI commands, and database queries.
98104
// Supports robust searching by language (python, sql) and customizable tags (regex, lambda, auth).
99105
public class UniversalSnippetService { }
106+
//list of strings as languages
107+
//list of strings as tags
108+
//snippet should probably the language(s), list of tags, the code snippet, and a description?

src/RandomAPI/Repository/IWebhookRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using RandomAPI.Models;
2+
using RandomAPI.Services.Webhooks;
23

34
namespace RandomAPI.Repository
45
{

src/RandomAPI/Repository/WebhookRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Data.Sqlite;
33
using RandomAPI.Models;
44
using System.Data;
5+
using RandomAPI.Services.Webhooks;
56

67
namespace RandomAPI.Repository
78
{

0 commit comments

Comments
 (0)