Skip to content

Commit a7ef822

Browse files
committed
Add full plugin details endpoint and refactor list views
Introduced /plugins/full endpoint for paginated, detailed plugin listings including versions, owners, tags, specifications, and operations. Added new MediatR request/handler/response types for this endpoint. Simplified the original plugin list response to exclude specifications and operations, keeping it as a summary view. Updated MediatorExtensions for easier access to the new functionality. #52
1 parent 1504190 commit a7ef822

7 files changed

Lines changed: 152 additions & 48 deletions

File tree

src/FlowSynx.PluginRegistry.Application/Extensions/MediatorExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginIcon;
55
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginLocation;
66
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginReadme;
7+
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsFullDetailsList;
78
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsList;
89
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsListByProfile;
910
using FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsStatisticsByProfile;
@@ -36,6 +37,16 @@ public static Task<PaginatedResult<PluginsListResponse>> PluginsList(
3637
return mediator.Send(new PluginsListRequest { Query = queryValue, Tag = tagValue, Page = page }, cancellationToken);
3738
}
3839

40+
public static Task<PaginatedResult<PluginsFullDetailsListResponse>> PluginsFullDetailsList(
41+
this IMediator mediator, int? page, int? pageSize, CancellationToken cancellationToken)
42+
{
43+
return mediator.Send(new PluginsFullDetailsListRequest
44+
{
45+
Page = page,
46+
PageSize = pageSize
47+
}, cancellationToken);
48+
}
49+
3950
public static Task<Result<PluginDetailsResponse>> PluginDetails(
4051
this IMediator mediator, string pluginType, string pluginVersion, CancellationToken cancellationToken)
4152
{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using FlowSynx.PluginRegistry.Application.Wrapper;
2+
using FlowSynx.PluginRegistry.Domain;
3+
using FlowSynx.PluginRegistry.Domain.Plugin;
4+
using MediatR;
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsFullDetailsList;
8+
9+
internal class PluginsFullDetailsListHandler : IRequestHandler<PluginsFullDetailsListRequest, PaginatedResult<PluginsFullDetailsListResponse>>
10+
{
11+
private readonly ILogger<PluginsFullDetailsListHandler> _logger;
12+
private readonly IPluginService _pluginService;
13+
14+
public PluginsFullDetailsListHandler(
15+
ILogger<PluginsFullDetailsListHandler> logger,
16+
IPluginService pluginService)
17+
{
18+
ArgumentNullException.ThrowIfNull(logger);
19+
ArgumentNullException.ThrowIfNull(pluginService);
20+
_logger = logger;
21+
_pluginService = pluginService;
22+
}
23+
24+
public async Task<PaginatedResult<PluginsFullDetailsListResponse>> Handle(PluginsFullDetailsListRequest request, CancellationToken cancellationToken)
25+
{
26+
try
27+
{
28+
Pagination<PluginEntity> plugins = await _pluginService.All(request.Page ?? 1, cancellationToken);
29+
30+
var response = plugins.Data.Select(p => new PluginsFullDetailsListResponse
31+
{
32+
Type = p.Type,
33+
Versions = p.Versions
34+
.OrderByDescending(x => x.LastModifiedOn)
35+
.ThenByDescending(x => x.CreatedOn)
36+
.Select(x => x.Version),
37+
LatestVersion = p.LatestVersion!.Version,
38+
Owners = p.Owners.Select(x=>x.Profile!.UserName),
39+
Description = p.LatestVersion!.Description,
40+
CategoryTitle = p.LatestVersion.PluginCategory.Title,
41+
LastUpdated = p.LastModifiedOn ?? p.CreatedOn,
42+
Tags = p.LatestVersion!.PluginVersionTags.Select(x => x.Tag!.Name),
43+
Specifications = p.LatestVersion!.Specifications.Select(x => new PluginsFullDetailsListSpecification
44+
{
45+
Name = x.Name,
46+
Description = x.Description,
47+
Type = x.Type,
48+
DefaultValue = x.DefaultValue,
49+
IsRequired = x.IsRequired
50+
}).ToList(),
51+
Operations = p.LatestVersion!.Operations.Select(x => new PluginsFullDetailsListOperation
52+
{
53+
Name = x.Name,
54+
Description = x.Description,
55+
Parameters = x.Parameters.Select(p => new PluginsFullDetailsListOperationParameter
56+
{
57+
Name = p.Name,
58+
Description = p.Description,
59+
Type = p.Type,
60+
DefaultValue = p.DefaultValue,
61+
IsRequired = p.IsRequired
62+
}).ToList()
63+
}).ToList(),
64+
TotalDownload = p.Versions.Sum(x=>x.Statistics.Count),
65+
IsTrusted = p.IsTrusted
66+
}).ToList();
67+
68+
return PaginatedResult<PluginsFullDetailsListResponse>.Success(response, plugins.TotalCount, request.Page ?? 1, plugins.PageSize);
69+
}
70+
catch (Exception ex)
71+
{
72+
_logger.LogError(ex.ToString());
73+
return PaginatedResult<PluginsFullDetailsListResponse>.Failure(ex.ToString());
74+
}
75+
}
76+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using FlowSynx.PluginRegistry.Application.Wrapper;
2+
using MediatR;
3+
4+
namespace FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsFullDetailsList;
5+
6+
public class PluginsFullDetailsListRequest : IRequest<PaginatedResult<PluginsFullDetailsListResponse>>
7+
{
8+
public int? Page { get; set; }
9+
public int? PageSize { get; set; }
10+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace FlowSynx.PluginRegistry.Application.Features.Plugins.Query.PluginsFullDetailsList;
2+
3+
public class PluginsFullDetailsListResponse
4+
{
5+
public required string Type { get; set; }
6+
public string? Description { get; set; }
7+
public IEnumerable<string> Versions { get; set; } = new List<string>();
8+
public string LatestVersion { get; set; } = string.Empty;
9+
public IEnumerable<string> Tags { get; set; } = new List<string>();
10+
public IEnumerable<string> Owners { get; set; } = new List<string>();
11+
public string? CategoryTitle { get; set; }
12+
public List<PluginsFullDetailsListSpecification> Specifications { get; set; } = new List<PluginsFullDetailsListSpecification>();
13+
public List<PluginsFullDetailsListOperation> Operations { get; set; } = new List<PluginsFullDetailsListOperation>();
14+
public DateTime LastUpdated { get; set; }
15+
public int TotalDownload { get; set; } = 0;
16+
public bool IsTrusted { get; set; } = false;
17+
}
18+
19+
public class PluginsFullDetailsListOperation
20+
{
21+
public string Name { get; set; } = string.Empty;
22+
public string? Description { get; set; }
23+
public List<PluginsFullDetailsListOperationParameter> Parameters { get; set; } = new List<PluginsFullDetailsListOperationParameter>();
24+
}
25+
26+
public class PluginsFullDetailsListOperationParameter
27+
{
28+
public string Name { get; set; } = string.Empty;
29+
public string? Description { get; set; }
30+
public string? Type { get; set; }
31+
public string? DefaultValue { get; set; }
32+
public bool? IsRequired { get; set; } = false;
33+
}
34+
35+
public class PluginsFullDetailsListSpecification
36+
{
37+
public string Name { get; set; } = string.Empty;
38+
public string? Description { get; set; }
39+
public string? Type { get; set; }
40+
public string? DefaultValue { get; set; }
41+
public bool? IsRequired { get; set; } = false;
42+
}

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsList/PluginsListHandler.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,6 @@ public async Task<PaginatedResult<PluginsListResponse>> Handle(PluginsListReques
4242
CategoryTitle = p.LatestVersion.PluginCategory.Title,
4343
LastUpdated = p.LastModifiedOn ?? p.CreatedOn,
4444
Tags = p.LatestVersion!.PluginVersionTags.Select(x => x.Tag!.Name),
45-
Specifications = p.LatestVersion!.Specifications.Select(x => new PluginsListSpecification
46-
{
47-
Name = x.Name,
48-
Description = x.Description,
49-
Type = x.Type,
50-
DefaultValue = x.DefaultValue,
51-
IsRequired = x.IsRequired
52-
}).ToList(),
53-
Operations = p.LatestVersion!.Operations.Select(x => new PluginsListOperation
54-
{
55-
Name = x.Name,
56-
Description = x.Description,
57-
Parameters = x.Parameters.Select(p => new PluginsListOperationParameter
58-
{
59-
Name = p.Name,
60-
Description = p.Description,
61-
Type = p.Type,
62-
DefaultValue = p.DefaultValue,
63-
IsRequired = p.IsRequired
64-
}).ToList()
65-
}).ToList(),
6645
TotalDownload = p.Versions.Sum(x=>x.Statistics.Count),
6746
IsTrusted = p.IsTrusted
6847
}).ToList();

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsList/PluginsListResponse.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,7 @@ public class PluginsListResponse
88
public IEnumerable<string> Tags { get; set; } = new List<string>();
99
public IEnumerable<string> Owners { get; set; } = new List<string>();
1010
public string? CategoryTitle { get; set; }
11-
public List<PluginsListSpecification> Specifications { get; set; } = new List<PluginsListSpecification>();
12-
public List<PluginsListOperation> Operations { get; set; } = new List<PluginsListOperation>();
1311
public DateTime LastUpdated { get; set; }
1412
public int TotalDownload { get; set; } = 0;
1513
public bool IsTrusted { get; set; } = false;
16-
}
17-
18-
public class PluginsListOperation
19-
{
20-
public string Name { get; set; } = string.Empty;
21-
public string? Description { get; set; }
22-
public List<PluginsListOperationParameter> Parameters { get; set; } = new List<PluginsListOperationParameter>();
23-
}
24-
25-
public class PluginsListOperationParameter
26-
{
27-
public string Name { get; set; } = string.Empty;
28-
public string? Description { get; set; }
29-
public string? Type { get; set; }
30-
public string? DefaultValue { get; set; }
31-
public bool? IsRequired { get; set; } = false;
32-
}
33-
34-
public class PluginsListSpecification
35-
{
36-
public string Name { get; set; } = string.Empty;
37-
public string? Description { get; set; }
38-
public string? Type { get; set; }
39-
public string? DefaultValue { get; set; }
40-
public bool? IsRequired { get; set; } = false;
4114
}

src/FlowSynx.Pluginregistry/Enhdpoints/Plugins.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public override void Map(WebApplication app)
1919
group.MapGet("", PluginsListAsync)
2020
.WithName("PluginsList");
2121

22+
group.MapGet("/full", PluginsFullDetailsListAsync)
23+
.WithName("PluginsFullDetailsList");
24+
2225
group.MapGet("/{type}/{version}", GetPluginWithTypeAsync)
2326
.WithName("GetPluginWithType");
2427

@@ -53,6 +56,16 @@ public async Task<IResult> PluginsListAsync(
5356
return result.Succeeded ? Results.Ok(result) : Results.NotFound(result);
5457
}
5558

59+
public async Task<IResult> PluginsFullDetailsListAsync(
60+
[FromQuery] int? page,
61+
[FromQuery] int? pageSize,
62+
[FromServices] IMediator mediator,
63+
CancellationToken cancellationToken)
64+
{
65+
var result = await mediator.PluginsFullDetailsList(page, pageSize, cancellationToken);
66+
return result.Succeeded ? Results.Ok(result) : Results.NotFound(result);
67+
}
68+
5669
public async Task<IResult> GetPluginWithTypeAsync(
5770
string type,
5871
string version,

0 commit comments

Comments
 (0)