Skip to content

Commit

Permalink
add 'batch' endpoint for creating activities
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeddy committed Jul 28, 2019
1 parent 0adbc7f commit 7c1ac2e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
21 changes: 20 additions & 1 deletion synprov/controllers/activities_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_activity(
): # noqa: E501
"""Create a new activity
Create a new Activity. If the passed Activity object contains a Used array, you must set the concreteType field of each Used subclass. # noqa: E501
Create a new Activity. # noqa: E501
:param body:
:type body: dict | bytes
Expand All @@ -27,6 +27,25 @@ def create_activity(
)


def create_activity_batch(
body
): # noqa: E501
"""Create multiple new activities
Create multiple new Activities. # noqa: E501
:param body:
:type body: list | bytes
:rtype: Node
"""
if connexion.request.is_json:
body = [ActivityForm.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
return controller.create_activity_batch(
body=body
)


def get_activities_graph(
sort_by='created_at',
order='desc',
Expand Down
13 changes: 13 additions & 0 deletions synprov/graph/controllers/activities_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ def create_activity(body=None): # noqa: E501
'properties': dict(act_node)
})

def create_activity_batch(
body
): # noqa: E501
"""Create multiple new activities
Create multiple new Activities. # noqa: E501
:param body:
:type body: list | bytes
:rtype: List[Node]
"""
return [create_activity(item) for item in body]

def get_activities_graph(sort_by=None, order=None, limit=None): # noqa: E501
"""Get provenance graph
Expand Down
28 changes: 26 additions & 2 deletions synprov/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ paths:
/activities:
post:
description: |-
Create a new Activity. If the passed Activity object contains a Used
array, you must set the concreteType field of each Used subclass.
Create a new Activity.
operationId: create_activity
requestBody:
content:
Expand All @@ -43,6 +42,31 @@ paths:
- Activities
x-codegen-request-body-name: body
x-openapi-router-controller: synprov.controllers.activities_controller
/activities/batch:
post:
description: |-
Create multiple new Activities.
operationId: create_activity_batch
requestBody:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/ActivityForm'
type: array
required: true
responses:
201:
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
description: Success — activity created
summary: Create multiple new activities
tags:
- Activities
x-codegen-request-body-name: body
x-openapi-router-controller: synprov.controllers.activities_controller
/activities/graph:
get:
description: |
Expand Down

0 comments on commit 7c1ac2e

Please sign in to comment.