From 915dbf176d22f53768913c769fc32a4d3a48225a Mon Sep 17 00:00:00 2001 From: crm-dhu Date: Thu, 12 Dec 2024 13:56:54 -0800 Subject: [PATCH] add an endpoint to check workflow status (#136) --- README.md | 17 +++++++++++++++-- orchard-ws/app/workflow/Controller.scala | 9 +++++++++ orchard-ws/app/workflow/Router.scala | 2 +- version.sbt | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 47ad2f0..b3e63b7 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ sdk env install sdk env # use brew to install postman (for API calls) and docker (if needed) -brew install -cask postman -brew install -cask docker +brew install --cask postman +brew install --cask docker ``` **Configure Postgres Database** @@ -103,6 +103,13 @@ Once generated, your `sample_workflow.json` can be used to create a workflow: ```html POST http://localhost:9001/v1/workflow ``` +OR +```sh +curl -X POST \ +-H "Content-type: application/json" \ +-d "$(jq -c . < path/to/sample_workflow.json)" \ +"http://localhost:9001/v1/workflow" +``` Which returns a workflow_id. For example: `wf-f231a08f-60e4-480a-b845-e53e06918f77` @@ -110,6 +117,12 @@ Once defined, activate a workflow using the workflow id like so: ```html PUT http://localhost:9001/v1/workflow/wf-f231a08f-60e4-480a-b845-e53e06918f77 ``` +OR +```sh +curl -X PUT \ +-H "Content-type: application/json" \ +"http://localhost:9001/v1/workflow/wf-f231a08f-60e4-480a-b845-e53e06918f77/activate" +``` **Resource and Activity Types** diff --git a/orchard-ws/app/workflow/Controller.scala b/orchard-ws/app/workflow/Controller.scala index 44a5c6f..7305ad1 100644 --- a/orchard-ws/app/workflow/Controller.scala +++ b/orchard-ws/app/workflow/Controller.scala @@ -309,6 +309,15 @@ class Controller @Inject() ( } } + def details(id: String) = userAction.async { + db.orchardDB + .async(new WorkflowQuery(id).get()) + .flatMap { + case Some(wf) => Future.successful(Ok(toResponse(wf))) + case _ => Future.successful(NotFound(Json.toJson(s"Workflow $id does not exist"))) + } + } + private def toResponse(r: WorkflowTable.R): JsValue = Json.toJson( WorkflowResponse( r.id, diff --git a/orchard-ws/app/workflow/Router.scala b/orchard-ws/app/workflow/Router.scala index d45aeb3..3143b38 100644 --- a/orchard-ws/app/workflow/Router.scala +++ b/orchard-ws/app/workflow/Router.scala @@ -28,7 +28,7 @@ class Router @Inject() (ctrl: Controller) extends SimpleRouter { ) => ctrl.filter(like, statuses, orderBy, order, page, perPage) - + case GET(p"/$id/details") => ctrl.details(id) case GET(p"/$id/activities") => ctrl.activities(id) case GET(p"/$id/activity/$actId") => ctrl.activityAttempts(id, actId) diff --git a/version.sbt b/version.sbt index c34bd42..1676e28 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -ThisBuild / version := "0.23.6" +ThisBuild / version := "0.24.0"