Skip to content

Commit ec19e5d

Browse files
chore: get relationship rules api endpint
1 parent 829c4ac commit ec19e5d

4 files changed

Lines changed: 196 additions & 2 deletions

File tree

‎apps/api/openapi/openapi.json‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5887,6 +5887,103 @@
58875887
}
58885888
},
58895889
"/v1/workspaces/{workspaceId}/relationship-rules": {
5890+
"get": {
5891+
"description": "Returns all relationship rules for the specified workspace.",
5892+
"operationId": "getRelationshipRules",
5893+
"parameters": [
5894+
{
5895+
"description": "ID of the workspace",
5896+
"in": "path",
5897+
"name": "workspaceId",
5898+
"required": true,
5899+
"schema": {
5900+
"type": "string"
5901+
}
5902+
},
5903+
{
5904+
"description": "Number of items to skip",
5905+
"in": "query",
5906+
"name": "offset",
5907+
"required": false,
5908+
"schema": {
5909+
"default": 0,
5910+
"minimum": 0,
5911+
"type": "integer"
5912+
}
5913+
},
5914+
{
5915+
"description": "Maximum number of items to return",
5916+
"in": "query",
5917+
"name": "limit",
5918+
"required": false,
5919+
"schema": {
5920+
"default": 50,
5921+
"maximum": 1000,
5922+
"minimum": 1,
5923+
"type": "integer"
5924+
}
5925+
}
5926+
],
5927+
"responses": {
5928+
"200": {
5929+
"content": {
5930+
"application/json": {
5931+
"schema": {
5932+
"properties": {
5933+
"items": {
5934+
"items": {
5935+
"$ref": "#/components/schemas/RelationshipRule"
5936+
},
5937+
"type": "array"
5938+
},
5939+
"limit": {
5940+
"description": "Maximum number of items returned",
5941+
"type": "integer"
5942+
},
5943+
"offset": {
5944+
"description": "Number of items skipped",
5945+
"type": "integer"
5946+
},
5947+
"total": {
5948+
"description": "Total number of items available",
5949+
"type": "integer"
5950+
}
5951+
},
5952+
"required": [
5953+
"items",
5954+
"total",
5955+
"limit",
5956+
"offset"
5957+
],
5958+
"type": "object"
5959+
}
5960+
}
5961+
},
5962+
"description": "Paginated list of items"
5963+
},
5964+
"400": {
5965+
"content": {
5966+
"application/json": {
5967+
"schema": {
5968+
"$ref": "#/components/schemas/ErrorResponse"
5969+
}
5970+
}
5971+
},
5972+
"description": "Invalid request"
5973+
},
5974+
"404": {
5975+
"content": {
5976+
"application/json": {
5977+
"schema": {
5978+
"$ref": "#/components/schemas/ErrorResponse"
5979+
}
5980+
}
5981+
},
5982+
"description": "Resource not found"
5983+
}
5984+
},
5985+
"summary": "Get relationship rules for a given workspace"
5986+
},
58905987
"post": {
58915988
"operationId": "createRelationshipRule",
58925989
"parameters": [

‎apps/api/openapi/paths/relationship-rules.jsonnet‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ local openapi = import '../lib/openapi.libsonnet';
22

33
{
44
'/v1/workspaces/{workspaceId}/relationship-rules': {
5+
get: {
6+
summary: 'Get relationship rules for a given workspace',
7+
operationId: 'getRelationshipRules',
8+
description: 'Returns all relationship rules for the specified workspace.',
9+
parameters: [
10+
openapi.workspaceIdParam(),
11+
openapi.offsetParam(),
12+
openapi.limitParam(),
13+
],
14+
responses: openapi.paginatedResponse(openapi.schemaRef('RelationshipRule'))
15+
+ openapi.notFoundResponse()
16+
+ openapi.badRequestResponse(),
17+
},
518
post: {
619
summary: 'Create relationship rule',
720
operationId: 'createRelationshipRule',

‎apps/api/src/routes/v1/workspaces/relationship-rules.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ import { v4 as uuidv4 } from "uuid";
77
import { Event, sendGoEvent } from "@ctrlplane/events";
88
import { getClientFor } from "@ctrlplane/workspace-engine-sdk";
99

10+
const listRelationshipRules: AsyncTypedHandler<
11+
"/v1/workspaces/{workspaceId}/relationship-rules",
12+
"get"
13+
> = async (req, res) => {
14+
const { workspaceId } = req.params;
15+
const { offset, limit } = req.query;
16+
17+
const response = await getClientFor(workspaceId).GET(
18+
"/v1/workspaces/{workspaceId}/relationship-rules",
19+
{ params: { path: { workspaceId }, query: { offset, limit } } },
20+
);
21+
22+
if (response.error != null)
23+
throw new ApiError(
24+
response.error.error ?? "Failed to list relationship rules",
25+
response.response.status,
26+
);
27+
28+
res.status(200).json(response.data);
29+
return;
30+
};
31+
1032
const createRelationshipRule: AsyncTypedHandler<
1133
"/v1/workspaces/{workspaceId}/relationship-rules",
1234
"post"
@@ -42,7 +64,10 @@ const getRelationshipRule: AsyncTypedHandler<
4264
);
4365

4466
if (response.error != null)
45-
throw new ApiError(response.error.error ?? "Relationship rule not found", response.response.status);
67+
throw new ApiError(
68+
response.error.error ?? "Relationship rule not found",
69+
response.response.status,
70+
);
4671

4772
res.status(200).json(response.data);
4873
};
@@ -99,6 +124,7 @@ const upsertRelationshipRule: AsyncTypedHandler<
99124
};
100125

101126
export const relationshipRulesRouter = Router({ mergeParams: true })
127+
.get("/", asyncHandler(listRelationshipRules))
102128
.post("/", asyncHandler(createRelationshipRule))
103129
.get("/:relationshipRuleId", asyncHandler(getRelationshipRule))
104130
.put("/:relationshipRuleId", asyncHandler(upsertRelationshipRule))

‎apps/api/src/types/openapi.ts‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ export interface paths {
467467
path?: never;
468468
cookie?: never;
469469
};
470-
get?: never;
470+
/**
471+
* Get relationship rules for a given workspace
472+
* @description Returns all relationship rules for the specified workspace.
473+
*/
474+
get: operations["getRelationshipRules"];
471475
put?: never;
472476
/** Create relationship rule */
473477
post: operations["createRelationshipRule"];
@@ -3792,6 +3796,60 @@ export interface operations {
37923796
};
37933797
};
37943798
};
3799+
getRelationshipRules: {
3800+
parameters: {
3801+
query?: {
3802+
/** @description Number of items to skip */
3803+
offset?: number;
3804+
/** @description Maximum number of items to return */
3805+
limit?: number;
3806+
};
3807+
header?: never;
3808+
path: {
3809+
/** @description ID of the workspace */
3810+
workspaceId: string;
3811+
};
3812+
cookie?: never;
3813+
};
3814+
requestBody?: never;
3815+
responses: {
3816+
/** @description Paginated list of items */
3817+
200: {
3818+
headers: {
3819+
[name: string]: unknown;
3820+
};
3821+
content: {
3822+
"application/json": {
3823+
items: components["schemas"]["RelationshipRule"][];
3824+
/** @description Maximum number of items returned */
3825+
limit: number;
3826+
/** @description Number of items skipped */
3827+
offset: number;
3828+
/** @description Total number of items available */
3829+
total: number;
3830+
};
3831+
};
3832+
};
3833+
/** @description Invalid request */
3834+
400: {
3835+
headers: {
3836+
[name: string]: unknown;
3837+
};
3838+
content: {
3839+
"application/json": components["schemas"]["ErrorResponse"];
3840+
};
3841+
};
3842+
/** @description Resource not found */
3843+
404: {
3844+
headers: {
3845+
[name: string]: unknown;
3846+
};
3847+
content: {
3848+
"application/json": components["schemas"]["ErrorResponse"];
3849+
};
3850+
};
3851+
};
3852+
};
37953853
createRelationshipRule: {
37963854
parameters: {
37973855
query?: never;

0 commit comments

Comments
 (0)