Skip to content

Commit 91a8e55

Browse files
net0wellclaude
andcommitted
feat(api): usedByPipelines na lista de Etapas e contrato pronto para o painel (spec 007)
- GET /stages traz usedByPipelines: trilhas com versão publicada que usam a Etapa (D-140). - Filtros de execuções e da auditoria com nomes de query em camelCase. - OpenAPI sem null nos enums e itens dos campos descritos; snapshot atualizado. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9186beb commit 91a8e55

7 files changed

Lines changed: 86 additions & 28 deletions

File tree

‎src/PythonScriptRunner.Abstractions/Management/CatalogAdmin.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ public sealed record StageVersionDetail
423423
/// <param name="LatestPublishedVersion">Latest published version.</param>
424424
/// <param name="DraftVersion">Version of the current draft.</param>
425425
/// <param name="UpdatedAt">Last change.</param>
426-
public sealed record StageSummary(string Key, string Name, string? Description, int? LatestPublishedVersion, int? DraftVersion, DateTimeOffset UpdatedAt);
426+
/// <param name="UsedByPipelines">Distinct pipelines with a published version that uses any version of the stage.</param>
427+
public sealed record StageSummary(
428+
string Key, string Name, string? Description, int? LatestPublishedVersion, int? DraftVersion, DateTimeOffset UpdatedAt, int UsedByPipelines);
427429

428430
/// <summary>A pipeline step that uses a stage version.</summary>
429431
/// <param name="PipelineKey">Pipeline key.</param>

‎src/PythonScriptRunner.Dashboard/Api/AdminEndpoints.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Reflection;
22
using Microsoft.AspNetCore.Builder;
33
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Mvc;
45
using Microsoft.AspNetCore.Routing;
56
using Microsoft.EntityFrameworkCore;
67
using Microsoft.Extensions.Options;
@@ -124,6 +125,13 @@ private static FieldTypesResponse BuildFieldTypes()
124125
}
125126
}
126127

127-
/// <summary>Filters of <c>GET /audit</c>.</summary>
128+
/// <summary>Filters of <c>GET /audit</c> (camelCase in the query, like the rest of the API).</summary>
128129
internal sealed record AuditListQuery(
129-
string? Actor, string? Action, string? EntityType, string? EntityKey, DateTimeOffset? From, DateTimeOffset? To, string? Cursor, int? Limit);
130+
[FromQuery(Name = "actor")] string? Actor,
131+
[FromQuery(Name = "action")] string? Action,
132+
[FromQuery(Name = "entityType")] string? EntityType,
133+
[FromQuery(Name = "entityKey")] string? EntityKey,
134+
[FromQuery(Name = "from")] DateTimeOffset? From,
135+
[FromQuery(Name = "to")] DateTimeOffset? To,
136+
[FromQuery(Name = "cursor")] string? Cursor,
137+
[FromQuery(Name = "limit")] int? Limit);

‎src/PythonScriptRunner.Dashboard/Api/DashboardOpenApi.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public static void Configure(OpenApiOptions options)
4747
{
4848
DescribeBindingSource(schema);
4949
}
50+
else if ((Nullable.GetUnderlyingType(type) ?? type).IsEnum && schema.Enum is { Count: > 0 } values)
51+
{
52+
// An optional enum query parameter (e.g. ?status=) makes the generator add null to the shared component;
53+
// the values in responses are never null.
54+
schema.Enum = [.. values.Where(v => v is not null)];
55+
}
5056

5157
return Task.CompletedTask;
5258
});

‎src/PythonScriptRunner.Dashboard/Api/RunEndpoints.cs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Globalization;
22
using Microsoft.AspNetCore.Builder;
33
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Mvc;
45
using Microsoft.AspNetCore.Routing;
56
using Microsoft.EntityFrameworkCore;
67
using PythonScriptRunner.EntityFrameworkCore;
@@ -93,9 +94,17 @@ private static async Task<IResult> DownloadAsync(ArtifactId id, HttpContext http
9394
}
9495
}
9596

96-
/// <summary>Filters of <c>GET /runs</c>.</summary>
97+
/// <summary>Filters of <c>GET /runs</c> (camelCase in the query, like the rest of the API).</summary>
9798
internal sealed record RunListQuery(
98-
string? PipelineKey, string? StageKey, RunKind? Kind, RunStatus? Status, RunTrigger? Trigger, DateTimeOffset? From, DateTimeOffset? To, string? Cursor, int? Limit);
99+
[FromQuery(Name = "pipelineKey")] string? PipelineKey,
100+
[FromQuery(Name = "stageKey")] string? StageKey,
101+
[FromQuery(Name = "kind")] RunKind? Kind,
102+
[FromQuery(Name = "status")] RunStatus? Status,
103+
[FromQuery(Name = "trigger")] RunTrigger? Trigger,
104+
[FromQuery(Name = "from")] DateTimeOffset? From,
105+
[FromQuery(Name = "to")] DateTimeOffset? To,
106+
[FromQuery(Name = "cursor")] string? Cursor,
107+
[FromQuery(Name = "limit")] int? Limit);
99108

100109
/// <summary>Computes <c>GET /overview</c> (D-115).</summary>
101110
internal sealed class OverviewQuery(IDbContextFactory<PsrDbContext> factory, IRunManager runs, TimeProvider time)

‎src/PythonScriptRunner.EntityFrameworkCore/Catalog/EfCatalogAdmin.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public async Task<Page<StageSummary>> ListStagesAsync(CatalogQuery query, Cancel
5959
.Select(s => new StageSummary(
6060
s.Key, s.Name, s.Description, s.LatestPublishedVersion,
6161
s.Versions.Where(v => v.Status == VersionStatus.Draft).Select(v => (int?)v.Version).FirstOrDefault(),
62-
s.UpdatedAt))
62+
s.UpdatedAt,
63+
db.PipelineSteps
64+
.Where(step => step.StageVersion.StageId == s.Id)
65+
.Join(db.PipelineVersions.Where(v => v.Status == VersionStatus.Published), step => step.PipelineVersionId, v => v.Id, (_, v) => v.PipelineId)
66+
.Distinct()
67+
.Count()))
6368
.ToListAsync(cancellationToken).ConfigureAwait(false);
6469
return new Page<StageSummary>(items, pageNumber, pageSize, total);
6570
}

‎tests/PythonScriptRunner.Dashboard.Tests/Snapshots/openapi-v1.verified.json‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,58 +238,58 @@
238238
"operationId": "ListAudit",
239239
"parameters": [
240240
{
241-
"name": "Actor",
241+
"name": "actor",
242242
"in": "query",
243243
"schema": {
244244
"type": "string"
245245
}
246246
},
247247
{
248-
"name": "Action",
248+
"name": "action",
249249
"in": "query",
250250
"schema": {
251251
"type": "string"
252252
}
253253
},
254254
{
255-
"name": "EntityType",
255+
"name": "entityType",
256256
"in": "query",
257257
"schema": {
258258
"type": "string"
259259
}
260260
},
261261
{
262-
"name": "EntityKey",
262+
"name": "entityKey",
263263
"in": "query",
264264
"schema": {
265265
"type": "string"
266266
}
267267
},
268268
{
269-
"name": "From",
269+
"name": "from",
270270
"in": "query",
271271
"schema": {
272272
"type": "string",
273273
"format": "date-time"
274274
}
275275
},
276276
{
277-
"name": "To",
277+
"name": "to",
278278
"in": "query",
279279
"schema": {
280280
"type": "string",
281281
"format": "date-time"
282282
}
283283
},
284284
{
285-
"name": "Cursor",
285+
"name": "cursor",
286286
"in": "query",
287287
"schema": {
288288
"type": "string"
289289
}
290290
},
291291
{
292-
"name": "Limit",
292+
"name": "limit",
293293
"in": "query",
294294
"schema": {
295295
"pattern": "^-?(?:0|[1-9]\\d*)$",
@@ -2002,65 +2002,65 @@
20022002
"operationId": "ListRuns",
20032003
"parameters": [
20042004
{
2005-
"name": "PipelineKey",
2005+
"name": "pipelineKey",
20062006
"in": "query",
20072007
"schema": {
20082008
"type": "string"
20092009
}
20102010
},
20112011
{
2012-
"name": "StageKey",
2012+
"name": "stageKey",
20132013
"in": "query",
20142014
"schema": {
20152015
"type": "string"
20162016
}
20172017
},
20182018
{
2019-
"name": "Kind",
2019+
"name": "kind",
20202020
"in": "query",
20212021
"schema": {
20222022
"$ref": "#/components/schemas/RunKind"
20232023
}
20242024
},
20252025
{
2026-
"name": "Status",
2026+
"name": "status",
20272027
"in": "query",
20282028
"schema": {
20292029
"$ref": "#/components/schemas/RunStatus"
20302030
}
20312031
},
20322032
{
2033-
"name": "Trigger",
2033+
"name": "trigger",
20342034
"in": "query",
20352035
"schema": {
20362036
"$ref": "#/components/schemas/RunTrigger"
20372037
}
20382038
},
20392039
{
2040-
"name": "From",
2040+
"name": "from",
20412041
"in": "query",
20422042
"schema": {
20432043
"type": "string",
20442044
"format": "date-time"
20452045
}
20462046
},
20472047
{
2048-
"name": "To",
2048+
"name": "to",
20492049
"in": "query",
20502050
"schema": {
20512051
"type": "string",
20522052
"format": "date-time"
20532053
}
20542054
},
20552055
{
2056-
"name": "Cursor",
2056+
"name": "cursor",
20572057
"in": "query",
20582058
"schema": {
20592059
"type": "string"
20602060
}
20612061
},
20622062
{
2063-
"name": "Limit",
2063+
"name": "limit",
20642064
"in": "query",
20652065
"schema": {
20662066
"pattern": "^-?(?:0|[1-9]\\d*)$",
@@ -3114,8 +3114,7 @@
31143114
"Reader",
31153115
"Executor",
31163116
"Author",
3117-
"Admin",
3118-
null
3117+
"Admin"
31193118
]
31203119
},
31213120
"ErrorKind": {
@@ -5183,7 +5182,8 @@
51835182
"description",
51845183
"latestPublishedVersion",
51855184
"draftVersion",
5186-
"updatedAt"
5185+
"updatedAt",
5186+
"usedByPipelines"
51875187
],
51885188
"type": "object",
51895189
"properties": {
@@ -5226,6 +5226,15 @@
52265226
"type": "string",
52275227
"description": "Last change.",
52285228
"format": "date-time"
5229+
},
5230+
"usedByPipelines": {
5231+
"pattern": "^-?(?:0|[1-9]\\d*)$",
5232+
"type": [
5233+
"integer",
5234+
"string"
5235+
],
5236+
"description": "Distinct pipelines with a published version that uses any version of the stage.",
5237+
"format": "int32"
52295238
}
52305239
},
52315240
"description": "A stage in a list."
@@ -5614,8 +5623,7 @@
56145623
"enum": [
56155624
"Draft",
56165625
"Published",
5617-
"Archived",
5618-
null
5626+
"Archived"
56195627
]
56205628
},
56215629
"VersionSummary": {

‎tests/PythonScriptRunner.EntityFrameworkCore.Tests/CatalogAdminTests.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ public async Task ImportCreatesDraftsAndExistingKeysGetANewVersion()
162162
.Code.ShouldBe(PsrErrorCodes.ImportInvalid);
163163
}
164164

165+
[Fact]
166+
public async Task StageList_CountsTheDistinctPipelinesWithAPublishedVersionThatUseTheStage()
167+
{
168+
await using var host = await PsrTestHost.CreateAsync(postgres, python);
169+
await host.PublishStageAsync("eco", Echo, [Text("texto")], [Text("texto")]);
170+
await host.PublishStageAsync("solta", Echo, [Text("texto")], [Text("texto")]);
171+
await host.PublishPipelineAsync("usa-eco", EchoPipeline());
172+
await host.PublishPipelineAsync("duas-versoes", EchoPipeline());
173+
var second = await host.Admin.CreatePipelineDraftFromAsync("duas-versoes", 1, PsrTestHost.Author, Ct);
174+
await host.Admin.PublishPipelineAsync("duas-versoes", second.Version, second.RowVersion, PsrTestHost.Author, Ct);
175+
await host.PublishPipelineAsync("arquivada", EchoPipeline());
176+
await host.Admin.ArchivePipelineVersionAsync("arquivada", 1, PsrTestHost.Author, Ct);
177+
var draft = await host.Admin.CreatePipelineAsync(new NewCatalogItem("so-rascunho", "Só rascunho"), PsrTestHost.Author, Ct);
178+
await host.Admin.SavePipelineDraftAsync("so-rascunho", draft.Version, EchoPipeline(), draft.RowVersion, PsrTestHost.Author, Ct);
179+
180+
var page = await host.Admin.ListStagesAsync(new CatalogQuery(), Ct);
181+
182+
page.Items.Select(s => (s.Key, s.UsedByPipelines)).ShouldBe([("eco", 2), ("solta", 0)]);
183+
}
184+
165185
private static PipelineDraftData EchoPipeline() => new()
166186
{
167187
Inputs = [Text("texto")],

0 commit comments

Comments
 (0)