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
44 changes: 41 additions & 3 deletions src/DotNetCore.CAP.Dashboard/RouteActionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public RouteActionProvider(IEndpointRouteBuilder builder, DashboardOptions optio
_agent = _serviceProvider.GetService<GatewayProxyAgent>(); // may be null
}

private IMonitoringApi MonitoringApi => _serviceProvider.GetRequiredService<IDataStorage>().GetMonitoringApi();
private IDataStorage DataStorage => _serviceProvider.GetRequiredService<IDataStorage>();
private IMonitoringApi MonitoringApi => DataStorage.GetMonitoringApi();

public void MapDashboardRoutes()
{
Expand All @@ -54,7 +55,9 @@ public void MapDashboardRoutes()
_builder.MapGet(prefixMatch + "/published/message/{id:long}", PublishedMessageDetails).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapGet(prefixMatch + "/received/message/{id:long}", ReceivedMessageDetails).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapPost(prefixMatch + "/published/requeue", PublishedRequeue).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapPost(prefixMatch + "/published/delete", PublishedDelete).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapPost(prefixMatch + "/received/reexecute", ReceivedRequeue).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapPost(prefixMatch + "/received/delete", ReceivedDelete).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapGet(prefixMatch + "/published/{status}", PublishedList).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapGet(prefixMatch + "/received/{status}", ReceivedList).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
_builder.MapGet(prefixMatch + "/subscriber", Subscribers).AllowAnonymousIf(_options.AllowAnonymousExplicit, _options.AuthorizationPolicy);
Expand All @@ -79,7 +82,7 @@ public async Task MetaInfo(HttpContext httpContext)
var cap = _serviceProvider.GetService<CapMarkerService>();
var broker = _serviceProvider.GetService<CapMessageQueueMakerService>();
var storage = _serviceProvider.GetService<CapStorageMarkerService>();

await httpContext.Response.WriteAsJsonAsync(new
{
cap,
Expand Down Expand Up @@ -215,6 +218,23 @@ public async Task PublishedRequeue(HttpContext httpContext)
httpContext.Response.StatusCode = StatusCodes.Status204NoContent;
}

public async Task PublishedDelete(HttpContext httpContext)
{
if (_agent != null && await _agent.Invoke(httpContext)) return;

var messageIds = await httpContext.Request.ReadFromJsonAsync<long[]>();
if (messageIds == null || messageIds.Length == 0)
{
httpContext.Response.StatusCode = StatusCodes.Status422UnprocessableEntity;
return;
}

foreach (var messageId in messageIds)
_ = await DataStorage.DeletePublishedMessageAsync(messageId);

httpContext.Response.StatusCode = StatusCodes.Status204NoContent;
}

public async Task ReceivedRequeue(HttpContext httpContext)
{
if (_agent != null && await _agent.Invoke(httpContext)) return;
Expand All @@ -236,6 +256,24 @@ public async Task ReceivedRequeue(HttpContext httpContext)
httpContext.Response.StatusCode = StatusCodes.Status204NoContent;
}

public async Task ReceivedDelete(HttpContext httpContext)
{
if (_agent != null && await _agent.Invoke(httpContext)) return;

var messageIds = await httpContext.Request.ReadFromJsonAsync<long[]>();
if (messageIds == null || messageIds.Length == 0)
{
httpContext.Response.StatusCode = StatusCodes.Status422UnprocessableEntity;
return;
}

foreach (var messageId in messageIds)
_ = await DataStorage.DeleteReceivedMessageAsync(messageId);

httpContext.Response.StatusCode = StatusCodes.Status204NoContent;
}


public async Task PublishedList(HttpContext httpContext)
{
if (_agent != null && await _agent.Invoke(httpContext)) return;
Expand Down Expand Up @@ -293,7 +331,7 @@ public async Task ReceivedList(HttpContext httpContext)
public async Task Subscribers(HttpContext httpContext)
{
if (_agent != null && await _agent.Invoke(httpContext)) return;

var cache = _serviceProvider.GetRequiredService<MethodMatcherCache>();
var subscribers = cache.GetCandidatesMethodsOfGroupNameGrouped();

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading