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
12 changes: 12 additions & 0 deletions apps/api/openapi/lib/openapi.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
},
},

orderParam():: {
name: 'order',
'in': 'query',
required: false,
description: 'Sort order for results',
schema: {
type: 'string',
enum: ['asc', 'desc'],
default: 'desc',
},
},

celParam():: {
name: 'cel',
'in': 'query',
Expand Down
14 changes: 14 additions & 0 deletions apps/api/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4784,6 +4784,20 @@
"minimum": 0,
"type": "integer"
}
},
{
"description": "Sort order for results",
"in": "query",
"name": "order",
"required": false,
"schema": {
"default": "desc",
"enum": [
"asc",
"desc"
],
"type": "string"
}
}
],
"responses": {
Expand Down
1 change: 1 addition & 0 deletions apps/api/openapi/paths/deploymentversions.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local openapi = import '../lib/openapi.libsonnet';
openapi.deploymentIdParam(),
openapi.limitParam(),
openapi.offsetParam(),
openapi.orderParam(),
],
responses: openapi.paginatedResponse(openapi.schemaRef('DeploymentVersion'))
+ openapi.notFoundResponse()
Expand Down
9 changes: 7 additions & 2 deletions apps/api/src/routes/v1/workspaces/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiError, asyncHandler } from "@/types/api.js";
import { Router } from "express";
import { v4 as uuidv4 } from "uuid";

import { and, count, eq, inArray, takeFirst } from "@ctrlplane/db";
import { and, asc, count, desc, eq, inArray, takeFirst } from "@ctrlplane/db";
import { db } from "@ctrlplane/db/client";
import {
enqueueDeploymentPlan,
Expand Down Expand Up @@ -291,6 +291,7 @@ const listDeploymentVersions: AsyncTypedHandler<
const { deploymentId } = req.params;
const limit = req.query.limit ?? 50;
const offset = req.query.offset ?? 0;
const order = req.query.order ?? "desc";

const [countResult] = await db
.select({ total: count() })
Expand All @@ -303,7 +304,11 @@ const listDeploymentVersions: AsyncTypedHandler<
.select()
.from(schema.deploymentVersion)
.where(eq(schema.deploymentVersion.deploymentId, deploymentId))
.orderBy(schema.deploymentVersion.createdAt)
.orderBy(
order === "asc"
? asc(schema.deploymentVersion.createdAt)
: desc(schema.deploymentVersion.createdAt),
)
.limit(limit)
.offset(offset);

Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/types/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,8 @@ export interface operations {
limit?: number;
/** @description Number of items to skip */
offset?: number;
/** @description Sort order for results */
order?: "asc" | "desc";
};
header?: never;
path: {
Expand Down
Loading