Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(orchestrator): implementation of getWorkflowById (v2) #1233

Merged
merged 1 commit into from
Feb 20, 2024
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
13 changes: 9 additions & 4 deletions plugins/orchestrator-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,22 @@ function setupInternalRoutes(
});
});

router.get('/workflows', async (_, res) => {
await V1.getWorkflows(services.sonataFlowService, services.dataIndexService)
router.get('/workflows/:workflowId', async (req, res) => {
const {
params: { workflowId },
} = req;
await V1.getWorkflowById(services.sonataFlowService, workflowId)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
});
});

// v2
api.register('getWorkflows', async (_c, _req, res, next) => {
await V2.getWorkflows(services.sonataFlowService, services.dataIndexService)
api.register('getWorkflowById', async (c, _req, res, next) => {
const workflowId = c.request.params.workflowId as string;

await V2.getWorkflowById(services.sonataFlowService, workflowId)
.then(result => res.json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,45 @@ const OPENAPI = `
}
}
},
"/v2/workflows/{workflowId}": {
"get": {
"operationId": "getWorkflowById",
"description": "Get a workflow by ID",
"parameters": [
{
"name": "workflowId",
"in": "path",
"description": "ID of the workflow to execute",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WorkflowDTO"
}
}
}
},
"500": {
"description": "Error workflow by id",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/v2/workflows/instances": {
"get": {
"operationId": "getInstances",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface paths {
/** Create or update a workflow */
post: operations['createWorkflow'];
};
'/v2/workflows/{workflowId}': {
/** @description Get a workflow by ID */
get: operations['getWorkflowById'];
};
'/v2/workflows/instances': {
/**
* Get instances
Expand Down Expand Up @@ -301,6 +305,29 @@ export interface operations {
};
};
};
/** @description Get a workflow by ID */
getWorkflowById: {
parameters: {
path: {
/** @description ID of the workflow to execute */
workflowId: string;
};
};
responses: {
/** @description Success */
200: {
content: {
'application/json': components['schemas']['WorkflowDTO'];
};
};
/** @description Error workflow by id */
500: {
content: {
'text/plain': string;
};
};
};
};
/**
* Get instances
* @description Retrieve an array of instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,94 @@ ifdef::internal-generation[]
endif::internal-generation[]


[.getWorkflowById]
==== getWorkflowById

`GET /v2/workflows/{workflowId}`



===== Description

Get a workflow by ID


// markup not found, no include::{specDir}v2/workflows/\{workflowId\}/GET/spec.adoc[opts=optional]



===== Parameters

====== Path Parameters

[cols="2,3,1,1,1"]
|===
|Name| Description| Required| Default| Pattern

| workflowId
| ID of the workflow to execute
| X
| null
|

|===






===== Return Type

<<WorkflowDTO>>


===== Content Type

* application/json
* text/plain

===== Responses

.HTTP Response Codes
[cols="2,3,1"]
|===
| Code | Message | Datatype


| 200
| Success
| <<WorkflowDTO>>


| 500
| Error workflow by id
| <<String>>

|===

===== Samples


// markup not found, no include::{snippetDir}v2/workflows/\{workflowId\}/GET/http-request.adoc[opts=optional]


// markup not found, no include::{snippetDir}v2/workflows/\{workflowId\}/GET/http-response.adoc[opts=optional]



// file not found, no * wiremock data link :v2/workflows/{workflowId}/GET/GET.json[]


ifdef::internal-generation[]
===== Implementation

// markup not found, no include::{specDir}v2/workflows/\{workflowId\}/GET/implementation.adoc[opts=optional]


endif::internal-generation[]


[.getWorkflowOverviewById]
==== getWorkflowOverviewById

Expand Down
24 changes: 24 additions & 0 deletions plugins/orchestrator-common/src/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ paths:
text/plain:
schema:
type: string
/v2/workflows/{workflowId}:
get:
operationId: getWorkflowById
description: Get a workflow by ID
parameters:
- name: workflowId
in: path
description: ID of the workflow to execute
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/WorkflowDTO'
'500':
description: Error workflow by id
content:
text/plain:
schema:
type: string
Comment on lines +126 to +131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to return an object instead of just plain text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but i'd like to change all the 500 definitions.
Can i do that in another PR?

/v2/workflows/instances:
get:
operationId: getInstances
Expand Down
Loading