diff --git a/src/RandomAPI/APIServices/ServiceInterfaces/IWebhookService.cs b/src/RandomAPI/APIServices/ServiceInterfaces/IWebhookService.cs index 4684ae5..685f202 100644 --- a/src/RandomAPI/APIServices/ServiceInterfaces/IWebhookService.cs +++ b/src/RandomAPI/APIServices/ServiceInterfaces/IWebhookService.cs @@ -1,49 +1,51 @@ using Microsoft.AspNetCore.Mvc; using RandomAPI.Models; -using RandomAPI.Services.Webhooks; - -public interface IWebhookService +namespace RandomAPI.Services.Webhooks { - // Basel class methods - /// - /// Sends a webhook notification to all registered listeners. - /// - Task BroadcastAsync(T payload) where T : class; + public interface IWebhookService + { + // Basel class methods + /// + /// Sends a webhook notification to all registered listeners. + /// + Task BroadcastAsync(T payload) where T : class; - /// - /// Registers a new webhook listener URL. - /// - /// True if added, false if it already existed. - Task AddListenerAsync(string url, WebhookType type = default); + /// + /// Registers a new webhook listener URL. + /// + /// True if added, false if it already existed. + Task AddListenerAsync(string url, WebhookType type = default); - /// - /// Removes a webhook listener URL. - /// - /// True if removed, false if not found. - Task RemoveListenerAsync(string url); + /// + /// Removes a webhook listener URL. + /// + /// True if removed, false if not found. + Task RemoveListenerAsync(string url); - /// - /// Returns a snapshot of all registered listener URLs. - /// - Task> GetListenersAsync(); + /// + /// Returns a snapshot of all registered listener URLs. + /// + Task> GetListenersAsync(); - /// - /// returns a snapshot of all registered listenrs of a given type - /// - /// the type of url - Task> GetListenersAsync(WebhookType type = WebhookType.Default); + /// + /// returns a snapshot of all registered listenrs of a given type + /// + /// the type of url + Task> GetListenersAsync(WebhookType type = WebhookType.Default); - // Controller Logic Methods (Implemented in the derived class) - public Task HandleGetListenersActionAsync(); - public Task HandleGetListenersOfTypeAsync(WebhookType type); - public Task HandleRegisterActionAsync(string url, WebhookType type = default); - public Task HandleUnregisterActionAsync(string url); - public Task HandleBroadcastActionAsync(IWebHookPayload payload); + // Controller Logic Methods (Implemented in the derived class) + public Task HandleGetListenersActionAsync(); + public Task HandleGetListenersOfTypeAsync(WebhookType type); + public Task HandleRegisterActionAsync(string url, WebhookType type = default); + public Task HandleUnregisterActionAsync(string url); + public Task HandleBroadcastActionAsync(IWebHookPayload payload); - public enum WebhookType - { - Default = 0, - Discord = 1, - Logging = 2, + public enum WebhookType + { + Default = 0, + Discord = 1, + Logging = 2, + } } } + diff --git a/src/RandomAPI/APIServices/Services/BaseWebhookService.cs b/src/RandomAPI/APIServices/Services/BaseWebhookService.cs index bcb1002..99ae0e6 100644 --- a/src/RandomAPI/APIServices/Services/BaseWebhookService.cs +++ b/src/RandomAPI/APIServices/Services/BaseWebhookService.cs @@ -1,5 +1,4 @@ using RandomAPI.Repository; -using static IWebhookService; namespace RandomAPI.Services.Webhooks { @@ -21,13 +20,13 @@ public async Task> GetListenersAsync() return urls.Select(u => u.Url); } - public async Task> GetListenersAsync(WebhookType type = WebhookType.Default) + public async Task> GetListenersAsync(IWebhookService.WebhookType type = IWebhookService.WebhookType.Default) { var urls = await _repo.GetUrlsOfTypeAsync(type); return urls.Select(u => u.Url); } - public async Task AddListenerAsync(string url, WebhookType type = default) + public async Task AddListenerAsync(string url, IWebhookService.WebhookType type = default) { await _repo.AddUrlAsync(url, type); } diff --git a/src/RandomAPI/APIServices/Services/WebhookActionService.cs b/src/RandomAPI/APIServices/Services/WebhookActionService.cs index 842b39b..b96268b 100644 --- a/src/RandomAPI/APIServices/Services/WebhookActionService.cs +++ b/src/RandomAPI/APIServices/Services/WebhookActionService.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc; using RandomAPI.Models; using RandomAPI.Repository; -using static IWebhookService; namespace RandomAPI.Services.Webhooks { @@ -16,7 +15,7 @@ public async Task HandleGetListenersActionAsync() return new OkObjectResult(urls); } - public async Task HandleGetListenersOfTypeAsync(WebhookType type) + public async Task HandleGetListenersOfTypeAsync(IWebhookService.WebhookType type) { var urls = await base.GetListenersAsync(type); return new OkObjectResult(urls); @@ -26,7 +25,7 @@ public async Task HandleRegisterActionAsync([FromBody] string url { if (string.IsNullOrWhiteSpace(url)) return new BadRequestObjectResult("URL cannot be empty."); - //neede both on regisdter and deregister + //needed both on regisdter and deregister string safeUrlForLog = SanitizeURL(ref url); await base.AddListenerAsync(url, type); @@ -89,7 +88,7 @@ public async Task HandleBroadcastActionAsync([FromBody] IWebHookP private static string SanitizeURL(ref string url) { url = url.Trim(); - var safeUrlForLog = url.Replace("\r", "").Replace("\n", ""); + string? safeUrlForLog = url.Replace("\r", "").Replace("\n", ""); return safeUrlForLog; } } diff --git a/src/RandomAPI/Controllers/WebhookController.cs b/src/RandomAPI/Controllers/WebhookController.cs index 229e6fb..0569960 100644 --- a/src/RandomAPI/Controllers/WebhookController.cs +++ b/src/RandomAPI/Controllers/WebhookController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; using RandomAPI.Services.Webhooks; -using static IWebhookService; + namespace RandomAPI.Controllers { @@ -43,7 +43,7 @@ public async Task RegisterUrl([FromBody] string url) [HttpPost("register-discord")] public async Task RegisterDiscordUrl([FromBody] string url) { - return await _webhookService.HandleRegisterActionAsync(url, WebhookType.Discord); + return await _webhookService.HandleRegisterActionAsync(url, IWebhookService.WebhookType.Discord); } /// diff --git a/src/RandomAPI/Models/WebhookUrl.cs b/src/RandomAPI/Models/WebhookUrl.cs index 49c1940..0993d5f 100644 --- a/src/RandomAPI/Models/WebhookUrl.cs +++ b/src/RandomAPI/Models/WebhookUrl.cs @@ -1,5 +1,5 @@  -namespace RandomAPI.Models +namespace RandomAPI.Services.Webhooks { /// /// Represents a registered webhook listener URL stored in the database. diff --git a/src/RandomAPI/Program.cs b/src/RandomAPI/Program.cs index 7e769de..c7e3100 100644 --- a/src/RandomAPI/Program.cs +++ b/src/RandomAPI/Program.cs @@ -78,6 +78,12 @@ // TODO: // - good logging service. rabapp has an event table, i bet i could do something worse +// 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 + +// idea - email checker that notifies me when a meeting time is moved or canceled for rabapp + +// + // - AlertGatewayService // API Endpoint Goal: POST / alert / ingest // Brief Description(Project Scope): Centralized Notification Hub with Discord Integration. @@ -97,3 +103,6 @@ public class HealthCheckService { } // A CRUD API to save and retrieve frequently forgotten code snippets, complex CLI commands, and database queries. // Supports robust searching by language (python, sql) and customizable tags (regex, lambda, auth). public class UniversalSnippetService { } +//list of strings as languages +//list of strings as tags +//snippet should probably the language(s), list of tags, the code snippet, and a description? diff --git a/src/RandomAPI/Repository/IWebhookRepository.cs b/src/RandomAPI/Repository/IWebhookRepository.cs index 9e9cbd7..6441b33 100644 --- a/src/RandomAPI/Repository/IWebhookRepository.cs +++ b/src/RandomAPI/Repository/IWebhookRepository.cs @@ -1,4 +1,5 @@ using RandomAPI.Models; +using RandomAPI.Services.Webhooks; namespace RandomAPI.Repository { diff --git a/src/RandomAPI/Repository/WebhookRepository.cs b/src/RandomAPI/Repository/WebhookRepository.cs index 5fa1d0a..104e685 100644 --- a/src/RandomAPI/Repository/WebhookRepository.cs +++ b/src/RandomAPI/Repository/WebhookRepository.cs @@ -2,6 +2,7 @@ using Microsoft.Data.Sqlite; using RandomAPI.Models; using System.Data; +using RandomAPI.Services.Webhooks; namespace RandomAPI.Repository {