Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions API/Controller/Admin/DTOs/AddWebhookDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenShock.API.Controller.Admin.DTOs;

public sealed class AddWebhookDto
{
public required string Name { get; set; }
public required Uri Url { get; set; }
}
23 changes: 23 additions & 0 deletions API/Controller/Admin/WebhookAdd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using OpenShock.API.Controller.Admin.DTOs;
using OpenShock.Common.Services.Webhook;

namespace OpenShock.API.Controller.Admin;

public sealed partial class AdminController
{
/// <summary>
/// Creates a webhook
/// </summary>
/// <response code="200">OK</response>
/// <response code="401">Unauthorized</response>
[HttpPost("webhooks")]
public async Task<IActionResult> AddWebhook([FromBody] AddWebhookDto body, [FromServices] IWebhookService webhookService)
{
var result = await webhookService.AddWebhook(body.Name, body.Url);
return result.Match<IActionResult>(
success => Ok(success.Value),
unsupported => BadRequest("Only discord webhooks are currently supported!")
);
}
}
20 changes: 20 additions & 0 deletions API/Controller/Admin/WebhookList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.Common.Models;
using OpenShock.Common.Services.Webhook;

namespace OpenShock.API.Controller.Admin;

public sealed partial class AdminController
{
/// <summary>
/// List webhooks
/// </summary>
/// <response code="200">OK</response>
/// <response code="401">Unauthorized</response>
[HttpGet("webhooks")]
public async Task<WebhookDto[]> ListWebhooks([FromServices] IWebhookService webhookService)
{
return await webhookService.GetWebhooks();
}
}
22 changes: 22 additions & 0 deletions API/Controller/Admin/WebhookRemove.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.Common.Services.Webhook;

namespace OpenShock.API.Controller.Admin;

public sealed partial class AdminController
{
/// <summary>
/// Removes a webhook
/// </summary>
/// <response code="200">OK</response>
/// <response code="401">Unauthorized</response>
[HttpDelete("webhooks/{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> RemoveWebhook([FromRoute] Guid id, [FromServices] IWebhookService webhookService)
{
bool removed = await webhookService.RemoveWebhook(id);
return removed ? Ok() : NotFound();
}
}
Loading